1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-06-15 22:57:12 +02:00

Improve entity searching algorithms.

This commit is contained in:
Sandu Liviu Catalin
2016-06-21 15:17:08 +03:00
parent 1d12ddd60d
commit 29af51c518
9 changed files with 1488 additions and 599 deletions

View File

@ -1,6 +1,5 @@
// ------------------------------------------------------------------------------------------------
#include "Entity/Blip.hpp"
#include "Base/Algo.hpp"
#include "Core.hpp"
// ------------------------------------------------------------------------------------------------
@ -287,100 +286,6 @@ static Object & Blip_Create(Int32 index, Int32 world, const Vector3 & pos, Int32
header, payload);
}
// ------------------------------------------------------------------------------------------------
static const Object & Blip_FindByID(Int32 id)
{
// Perform a range check on the specified identifier
if (INVALID_ENTITYEX(id, SQMOD_BLIP_POOL))
STHROWF("The specified blip identifier is invalid: %d", id);
// Obtain the ends of the entity pool
Core::Blips::const_iterator itr = Core::Get().GetBlips().cbegin();
Core::Blips::const_iterator end = Core::Get().GetBlips().cend();
// Process each entity in the pool
for (; itr != end; ++itr)
{
// Does the identifier match the specified one?
if (itr->mID == id)
{
return itr->mObj; // Stop searching and return this entity
}
}
// Unable to locate a blip matching the specified identifier
return NullObject();
}
static const Object & Blip_FindByTag(CSStr tag)
{
// Perform a validity check on the specified tag
if (!tag || *tag == '\0')
{
STHROWF("The specified blip tag is invalid: null/empty");
}
// Obtain the ends of the entity pool
Core::Blips::const_iterator itr = Core::Get().GetBlips().cbegin();
Core::Blips::const_iterator end = Core::Get().GetBlips().cend();
// Process each entity in the pool
for (; itr != end; ++itr)
{
// Does this entity even exist and does the tag match the specified one?
if (itr->mInst != nullptr && itr->mInst->GetTag().compare(tag) == 0)
{
return itr->mObj; // Stop searching and return this entity
}
}
// Unable to locate a blip matching the specified tag
return NullObject();
}
// ------------------------------------------------------------------------------------------------
static const Object & Blip_FindBySprID(Int32 sprid)
{
// Perform a range check on the specified identifier
if (sprid < 0)
{
STHROWF("The specified sprite identifier is invalid: %d", sprid);
}
// Obtain the ends of the entity pool
Core::Blips::const_iterator itr = Core::Get().GetBlips().cbegin();
Core::Blips::const_iterator end = Core::Get().GetBlips().cend();
// Process each entity in the pool
for (; itr != end; ++itr)
{
// Does the identifier match the specified one?
if (itr->mSprID == sprid)
{
return itr->mObj; // Stop searching and return this entity
}
}
// Unable to locate a blip matching the specified identifier
return NullObject();
}
// ------------------------------------------------------------------------------------------------
static Array Blip_FindActive()
{
const StackGuard sg;
// Allocate an empty array on the stack
sq_newarray(DefaultVM::Get(), 0);
// Process each entity in the pool
Algo::Collect(Core::Get().GetBlips().cbegin(), Core::Get().GetBlips().cend(),
[](Core::Blips::const_reference inst) -> bool {
return VALID_ENTITY(inst.mID);
},
[](Core::Blips::const_reference inst) -> void {
// Push the script object on the stack
sq_pushobject(DefaultVM::Get(), inst.mObj.GetObject());
// Append the object at the back of the array
if (SQ_FAILED(sq_arrayappend(DefaultVM::Get(), -2)))
{
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_CBlip(HSQUIRRELVM vm)
{
@ -418,11 +323,6 @@ void Register_CBlip(HSQUIRRELVM vm)
.Prop(_SC("Green"), &CBlip::GetColorG)
.Prop(_SC("Blue"), &CBlip::GetColorB)
.Prop(_SC("Alpha"), &CBlip::GetColorA)
// Static Functions
.StaticFunc(_SC("FindByID"), &Blip_FindByID)
.StaticFunc(_SC("FindByTag"), &Blip_FindByTag)
.StaticFunc(_SC("FindActive"), &Blip_FindActive)
.StaticFunc(_SC("FindBySprID"), &Blip_FindBySprID)
// Static Overloads
.StaticOverload< Object & (*)(Int32, Float32, Float32, Float32, Int32, Uint8, Uint8, Uint8, Uint8, Int32) >
(_SC("CreateEx"), &Blip_CreateEx)

View File

@ -1,7 +1,6 @@
// ------------------------------------------------------------------------------------------------
#include "Entity/Checkpoint.hpp"
#include "Entity/Player.hpp"
#include "Base/Algo.hpp"
#include "Base/Color4.hpp"
#include "Base/Vector3.hpp"
#include "Core.hpp"
@ -482,79 +481,6 @@ static Object & Checkpoint_Create(CPlayer & player, Int32 world, bool sphere, co
color.r, color.g, color.b, color.a, radius, header, payload);
}
// ------------------------------------------------------------------------------------------------
static const Object & Checkpoint_FindByID(Int32 id)
{
// Perform a range check on the specified identifier
if (INVALID_ENTITYEX(id, SQMOD_CHECKPOINT_POOL))
{
STHROWF("The specified checkpoint identifier is invalid: %d", id);
}
// Obtain the ends of the entity pool
Core::Checkpoints::const_iterator itr = Core::Get().GetCheckpoints().cbegin();
Core::Checkpoints::const_iterator end = Core::Get().GetCheckpoints().cend();
// Process each entity in the pool
for (; itr != end; ++itr)
{
// Does the identifier match the specified one?
if (itr->mID == id)
{
return itr->mObj; // Stop searching and return this entity
}
}
// Unable to locate a checkpoint matching the specified identifier
return NullObject();
}
// ------------------------------------------------------------------------------------------------
static const Object & Checkpoint_FindByTag(CSStr tag)
{
// Perform a validity check on the specified tag
if (!tag || *tag == '\0')
{
STHROWF("The specified checkpoint tag is invalid: null/empty");
}
// Obtain the ends of the entity pool
Core::Checkpoints::const_iterator itr = Core::Get().GetCheckpoints().cbegin();
Core::Checkpoints::const_iterator end = Core::Get().GetCheckpoints().cend();
// Process each entity in the pool
for (; itr != end; ++itr)
{
// Does this entity even exist and does the tag match the specified one?
if (itr->mInst != nullptr && itr->mInst->GetTag().compare(tag) == 0)
{
return itr->mObj; // Stop searching and return this entity
}
}
// Unable to locate a checkpoint matching the specified tag
return NullObject();
}
// ------------------------------------------------------------------------------------------------
static Array Checkpoint_FindActive()
{
const StackGuard sg;
// Allocate an empty array on the stack
sq_newarray(DefaultVM::Get(), 0);
// Process each entity in the pool
Algo::Collect(Core::Get().GetCheckpoints().cbegin(), Core::Get().GetCheckpoints().cend(),
[](Core::Checkpoints::const_reference inst) -> bool {
return VALID_ENTITY(inst.mID);
},
[](Core::Checkpoints::const_reference inst) -> void {
// Push the script object on the stack
sq_pushobject(DefaultVM::Get(), inst.mObj.GetObject());
// Append the object at the back of the array
if (SQ_FAILED(sq_arrayappend(DefaultVM::Get(), -2)))
{
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_CCheckpoint(HSQUIRRELVM vm)
{
@ -603,10 +529,6 @@ void Register_CCheckpoint(HSQUIRRELVM vm)
(_SC("SetColor"), &CCheckpoint::SetColorEx)
.Overload< void (CCheckpoint::*)(Uint8, Uint8, Uint8, Uint8) const >
(_SC("SetColor"), &CCheckpoint::SetColorEx)
// Static Functions
.StaticFunc(_SC("FindByID"), &Checkpoint_FindByID)
.StaticFunc(_SC("FindByTag"), &Checkpoint_FindByTag)
.StaticFunc(_SC("FindActive"), &Checkpoint_FindActive)
// Static Overloads
.StaticOverload< Object & (*)(CPlayer &, Int32, bool, Float32, Float32, Float32, Uint8, Uint8, Uint8, Uint8, Float32) >
(_SC("CreateEx"), &Checkpoint_CreateEx)

View File

@ -1,6 +1,5 @@
// ------------------------------------------------------------------------------------------------
#include "Entity/Keybind.hpp"
#include "Base/Algo.hpp"
#include "Core.hpp"
// ------------------------------------------------------------------------------------------------
@ -180,79 +179,6 @@ static Object & Keybind_Create(bool release, Int32 primary, Int32 secondary, Int
return Core::Get().NewKeybind(-1, release, primary, secondary, alternative, header, payload);
}
// ------------------------------------------------------------------------------------------------
static const Object & Keybind_FindByID(Int32 id)
{
// Perform a range check on the specified identifier
if (INVALID_ENTITYEX(id, SQMOD_KEYBIND_POOL))
{
STHROWF("The specified keybind identifier is invalid: %d", id);
}
// Obtain the ends of the entity pool
Core::Keybinds::const_iterator itr = Core::Get().GetKeybinds().cbegin();
Core::Keybinds::const_iterator end = Core::Get().GetKeybinds().cend();
// Process each entity in the pool
for (; itr != end; ++itr)
{
// Does the identifier match the specified one?
if (itr->mID == id)
{
return itr->mObj; // Stop searching and return this entity
}
}
// Unable to locate a keybind matching the specified identifier
return NullObject();
}
// ------------------------------------------------------------------------------------------------
static const Object & Keybind_FindByTag(CSStr tag)
{
// Perform a validity check on the specified tag
if (!tag || *tag == '\0')
{
STHROWF("The specified keybind tag is invalid: null/empty");
}
// Obtain the ends of the entity pool
Core::Keybinds::const_iterator itr = Core::Get().GetKeybinds().cbegin();
Core::Keybinds::const_iterator end = Core::Get().GetKeybinds().cend();
// Process each entity in the pool
for (; itr != end; ++itr)
{
// Does this entity even exist and does the tag match the specified one?
if (itr->mInst != nullptr && itr->mInst->GetTag().compare(tag) == 0)
{
return itr->mObj; // Stop searching and return this entity
}
}
// Unable to locate a keybind matching the specified tag
return NullObject();
}
// ------------------------------------------------------------------------------------------------
static Array Keybind_FindActive()
{
const StackGuard sg;
// Allocate an empty array on the stack
sq_newarray(DefaultVM::Get(), 0);
// Process each entity in the pool
Algo::Collect(Core::Get().GetKeybinds().cbegin(), Core::Get().GetKeybinds().cend(),
[](Core::Keybinds::const_reference inst) -> bool {
return VALID_ENTITY(inst.mID);
},
[](Core::Keybinds::const_reference inst) -> void {
// Push the script object on the stack
sq_pushobject(DefaultVM::Get(), inst.mObj.GetObject());
// Append the object at the back of the array
if (SQ_FAILED(sq_arrayappend(DefaultVM::Get(), -2)))
{
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;
}
// ------------------------------------------------------------------------------------------------
static SQInteger Keybind_UnusedSlot()
{
@ -287,9 +213,6 @@ void Register_CKeybind(HSQUIRRELVM vm)
.Prop(_SC("Third"), &CKeybind::GetThird)
.Prop(_SC("Release"), &CKeybind::IsRelease)
// Static Functions
.StaticFunc(_SC("FindByID"), &Keybind_FindByID)
.StaticFunc(_SC("FindByTag"), &Keybind_FindByTag)
.StaticFunc(_SC("FindActive"), &Keybind_FindActive)
.StaticFunc(_SC("UnusedSlot"), &Keybind_UnusedSlot)
// Static Overloads
.StaticOverload< Object & (*)(Int32, bool, Int32, Int32, Int32) >

View File

@ -1,7 +1,6 @@
// ------------------------------------------------------------------------------------------------
#include "Entity/Object.hpp"
#include "Entity/Player.hpp"
#include "Base/Algo.hpp"
#include "Base/Quaternion.hpp"
#include "Base/Vector3.hpp"
#include "Core.hpp"
@ -808,77 +807,6 @@ static Object & Object_Create(Int32 model, Int32 world, const Vector3 & pos, Int
return Core::Get().NewObject(model, world, pos.x, pos.y, pos.z, alpha, header, payload);
}
// ------------------------------------------------------------------------------------------------
static const Object & Object_FindByID(Int32 id)
{
// Perform a range check on the specified identifier
if (INVALID_ENTITYEX(id, SQMOD_OBJECT_POOL))
{
STHROWF("The specified object identifier is invalid: %d", id);
}
// Obtain the ends of the entity pool
Core::Objects::const_iterator itr = Core::Get().GetObjects().cbegin();
Core::Objects::const_iterator end = Core::Get().GetObjects().cend();
// Process each entity in the pool
for (; itr != end; ++itr)
{
// Does the identifier match the specified one?
if (itr->mID == id)
{
return itr->mObj; // Stop searching and return this entity
}
}
// Unable to locate a object matching the specified identifier
return NullObject();
}
// ------------------------------------------------------------------------------------------------
static const Object & Object_FindByTag(CSStr tag)
{
// Perform a validity check on the specified tag
if (!tag || *tag == '\0')
STHROWF("The specified object tag is invalid: null/empty");
// Obtain the ends of the entity pool
Core::Objects::const_iterator itr = Core::Get().GetObjects().cbegin();
Core::Objects::const_iterator end = Core::Get().GetObjects().cend();
// Process each entity in the pool
for (; itr != end; ++itr)
{
// Does this entity even exist and does the tag match the specified one?
if (itr->mInst != nullptr && itr->mInst->GetTag().compare(tag) == 0)
{
return itr->mObj; // Stop searching and return this entity
}
}
// Unable to locate a object matching the specified tag
return NullObject();
}
// ------------------------------------------------------------------------------------------------
static Array Object_FindActive()
{
const StackGuard sg;
// Allocate an empty array on the stack
sq_newarray(DefaultVM::Get(), 0);
// Process each entity in the pool
Algo::Collect(Core::Get().GetObjects().cbegin(), Core::Get().GetObjects().cend(),
[](Core::Objects::const_reference inst) -> bool {
return VALID_ENTITY(inst.mID);
},
[](Core::Objects::const_reference inst) -> void {
// Push the script object on the stack
sq_pushobject(DefaultVM::Get(), inst.mObj.GetObject());
// Append the object at the back of the array
if (SQ_FAILED(sq_arrayappend(DefaultVM::Get(), -2)))
{
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_CObject(HSQUIRRELVM vm)
{
@ -980,10 +908,6 @@ void Register_CObject(HSQUIRRELVM vm)
(_SC("RotateByEuler"), &CObject::RotateByEuler)
.Overload< void (CObject::*)(Float32, Float32, Float32, Uint32) const >
(_SC("RotateByEuler"), &CObject::RotateByEulerEx)
// Static Functions
.StaticFunc(_SC("FindByID"), &Object_FindByID)
.StaticFunc(_SC("FindByTag"), &Object_FindByTag)
.StaticFunc(_SC("FindActive"), &Object_FindActive)
// Static Overloads
.StaticOverload< Object & (*)(Int32, Int32, Float32, Float32, Float32, Int32) >
(_SC("CreateEx"), &Object_CreateEx)

View File

@ -1,7 +1,6 @@
// ------------------------------------------------------------------------------------------------
#include "Entity/Pickup.hpp"
#include "Entity/Player.hpp"
#include "Base/Algo.hpp"
#include "Base/Vector3.hpp"
#include "Core.hpp"
@ -368,79 +367,6 @@ static Object & Pickup_Create(Int32 model, Int32 world, Int32 quantity, const Ve
header, payload);
}
// ------------------------------------------------------------------------------------------------
static const Object & Pickup_FindByID(Int32 id)
{
// Perform a range check on the specified identifier
if (INVALID_ENTITYEX(id, SQMOD_PICKUP_POOL))
{
STHROWF("The specified pickup identifier is invalid: %d", id);
}
// Obtain the ends of the entity pool
Core::Pickups::const_iterator itr = Core::Get().GetPickups().cbegin();
Core::Pickups::const_iterator end = Core::Get().GetPickups().cend();
// Process each entity in the pool
for (; itr != end; ++itr)
{
// Does the identifier match the specified one?
if (itr->mID == id)
{
return itr->mObj; // Stop searching and return this entity
}
}
// Unable to locate a pickup matching the specified identifier
return NullObject();
}
// ------------------------------------------------------------------------------------------------
static const Object & Pickup_FindByTag(CSStr tag)
{
// Perform a validity check on the specified tag
if (!tag || *tag == '0')
{
STHROWF("The specified pickup tag is invalid: null/empty");
}
// Obtain the ends of the entity pool
Core::Pickups::const_iterator itr = Core::Get().GetPickups().cbegin();
Core::Pickups::const_iterator end = Core::Get().GetPickups().cend();
// Process each entity in the pool
for (; itr != end; ++itr)
{
// Does this entity even exist and does the tag match the specified one?
if (itr->mInst != nullptr && itr->mInst->GetTag().compare(tag) == 0)
{
return itr->mObj; // Stop searching and return this entity
}
}
// Unable to locate a pickup matching the specified tag
return NullObject();
}
// ------------------------------------------------------------------------------------------------
static Array Pickup_FindActive()
{
const StackGuard sg;
// Allocate an empty array on the stack
sq_newarray(DefaultVM::Get(), 0);
// Process each entity in the pool
Algo::Collect(Core::Get().GetPickups().cbegin(), Core::Get().GetPickups().cend(),
[](Core::Pickups::const_reference inst) -> bool {
return VALID_ENTITY(inst.mID);
},
[](Core::Pickups::const_reference inst) -> void {
// Push the script object on the stack
sq_pushobject(DefaultVM::Get(), inst.mObj.GetObject());
// Append the object at the back of the array
if (SQ_FAILED(sq_arrayappend(DefaultVM::Get(), -2)))
{
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_CPickup(HSQUIRRELVM vm)
{
@ -482,10 +408,6 @@ void Register_CPickup(HSQUIRRELVM vm)
.Func(_SC("Refresh"), &CPickup::Refresh)
.Func(_SC("SetPos"), &CPickup::SetPositionEx)
.Func(_SC("SetPosition"), &CPickup::SetPositionEx)
// Static Functions
.StaticFunc(_SC("FindByID"), &Pickup_FindByID)
.StaticFunc(_SC("FindByTag"), &Pickup_FindByTag)
.StaticFunc(_SC("FindActive"), &Pickup_FindActive)
// Static Overloads
.StaticOverload< Object & (*)(Int32, Int32, Int32, Float32, Float32, Float32, Int32, bool) >
(_SC("CreateEx"), &Pickup_CreateEx)

View File

@ -1,7 +1,6 @@
// ------------------------------------------------------------------------------------------------
#include "Entity/Player.hpp"
#include "Entity/Vehicle.hpp"
#include "Base/Algo.hpp"
#include "Base/Color3.hpp"
#include "Base/Color4.hpp"
#include "Base/Vector3.hpp"
@ -2062,110 +2061,6 @@ SQInteger CPlayer::AnnounceEx(HSQUIRRELVM vm)
return 0;
}
// ------------------------------------------------------------------------------------------------
static const Object & Player_FindByID(Int32 id)
{
// Perform a range check on the specified identifier
if (INVALID_ENTITYEX(id, SQMOD_PLAYER_POOL))
{
STHROWF("The specified player identifier is invalid: %d", id);
}
// Obtain the ends of the entity pool
Core::Players::const_iterator itr = Core::Get().GetPlayers().cbegin();
Core::Players::const_iterator end = Core::Get().GetPlayers().cend();
// Process each entity in the pool
for (; itr != end; ++itr)
{
// Does the identifier match the specified one?
if (itr->mID == id)
{
return itr->mObj; // Stop searching and return this entity
}
}
// Unable to locate a player matching the specified identifier
return NullObject();
}
// ------------------------------------------------------------------------------------------------
static const Object & Player_FindByTag(CSStr tag)
{
// Perform a validity check on the specified tag
if (!tag || *tag == '\0')
{
STHROWF("The specified player tag is invalid: null/empty");
}
// Obtain the ends of the entity pool
Core::Players::const_iterator itr = Core::Get().GetPlayers().cbegin();
Core::Players::const_iterator end = Core::Get().GetPlayers().cend();
// Process each entity in the pool
for (; itr != end; ++itr)
{
// Does this entity even exist and does the tag match the specified one?
if (itr->mInst != nullptr && itr->mInst->GetTag().compare(tag) == 0)
{
return itr->mObj; // Stop searching and return this entity
}
}
// Unable to locate a player matching the specified tag
return NullObject();
}
// ------------------------------------------------------------------------------------------------
static Array Player_FindActive()
{
const StackGuard sg;
// Allocate an empty array on the stack
sq_newarray(DefaultVM::Get(), 0);
// Process each entity in the pool
Algo::Collect(Core::Get().GetPlayers().cbegin(), Core::Get().GetPlayers().cend(),
[](Core::Players::const_reference inst) -> bool {
return VALID_ENTITY(inst.mID);
},
[](Core::Players::const_reference inst) -> void {
// Push the script object on the stack
sq_pushobject(DefaultVM::Get(), inst.mObj.GetObject());
// Append the object at the back of the array
if (SQ_FAILED(sq_arrayappend(DefaultVM::Get(), -2)))
{
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;
}
// ------------------------------------------------------------------------------------------------
static const Object & Player_FindAuto(Object & by)
{
switch (by.GetType())
{
case OT_INTEGER:
{
return Core::Get().GetPlayer(by.Cast< Int32 >()).mObj;
} break;
case OT_FLOAT:
{
return Core::Get().GetPlayer(std::round(by.Cast< Float32 >())).mObj;
} break;
case OT_STRING:
{
// Obtain the argument as a string
String str(by.Cast< String >());
// Attempt to locate the player with this name
Int32 id = _Func->GetPlayerIdFromName(&str[0]);
// Was there a player with this name?
if (VALID_ENTITYEX(id, SQMOD_PLAYER_POOL))
{
Core::Get().GetPlayer(id).mObj;
}
} break;
default: STHROWF("Unsupported search identifier");
}
// Default to a null object
return NullObject();
}
// ================================================================================================
void Register_CPlayer(HSQUIRRELVM vm)
{
@ -2334,11 +2229,6 @@ void Register_CPlayer(HSQUIRRELVM vm)
.SquirrelFunc(_SC("AnnounceEx"), &CPlayer::AnnounceEx)
.SquirrelFunc(_SC("Text"), &CPlayer::Announce)
.SquirrelFunc(_SC("TextEx"), &CPlayer::AnnounceEx)
// Static Functions
.StaticFunc(_SC("Find"), &Player_FindAuto)
.StaticFunc(_SC("FindByID"), &Player_FindByID)
.StaticFunc(_SC("FindByTag"), &Player_FindByTag)
.StaticFunc(_SC("FindActive"), &Player_FindActive)
);
}

View File

@ -1,7 +1,6 @@
// ------------------------------------------------------------------------------------------------
#include "Entity/Vehicle.hpp"
#include "Entity/Player.hpp"
#include "Base/Algo.hpp"
#include "Base/Quaternion.hpp"
#include "Base/Vector2.hpp"
#include "Base/Vector3.hpp"
@ -1625,79 +1624,6 @@ static Object & Vehicle_Create(Int32 model, Int32 world, const Vector3 & pos, Fl
header, payload);
}
// ------------------------------------------------------------------------------------------------
static const Object & Vehicle_FindByID(Int32 id)
{
// Perform a range check on the specified identifier
if (INVALID_ENTITYEX(id, SQMOD_VEHICLE_POOL))
{
STHROWF("The specified vehicle identifier is invalid: %d", id);
}
// Obtain the ends of the entity pool
Core::Vehicles::const_iterator itr = Core::Get().GetVehicles().cbegin();
Core::Vehicles::const_iterator end = Core::Get().GetVehicles().cend();
// Process each entity in the pool
for (; itr != end; ++itr)
{
// Does the identifier match the specified one?
if (itr->mID == id)
{
return itr->mObj; // Stop searching and return this entity
}
}
// Unable to locate a vehicle matching the specified identifier
return NullObject();
}
// ------------------------------------------------------------------------------------------------
static const Object & Vehicle_FindByTag(CSStr tag)
{
// Perform a validity check on the specified tag
if (!tag || *tag == '\0')
{
STHROWF("The specified vehicle tag is invalid: null/empty");
}
// Obtain the ends of the entity pool
Core::Vehicles::const_iterator itr = Core::Get().GetVehicles().cbegin();
Core::Vehicles::const_iterator end = Core::Get().GetVehicles().cend();
// Process each entity in the pool
for (; itr != end; ++itr)
{
// Does this entity even exist and does the tag match the specified one?
if (itr->mInst != nullptr && itr->mInst->GetTag().compare(tag) == 0)
{
return itr->mObj; // Stop searching and return this entity
}
}
// Unable to locate a vehicle matching the specified tag
return NullObject();
}
// ------------------------------------------------------------------------------------------------
static Array Vehicle_FindActive()
{
const StackGuard sg;
// Allocate an empty array on the stack
sq_newarray(DefaultVM::Get(), 0);
// Process each entity in the pool
Algo::Collect(Core::Get().GetVehicles().cbegin(), Core::Get().GetVehicles().cend(),
[](Core::Vehicles::const_reference inst) -> bool {
return VALID_ENTITY(inst.mID);
},
[](Core::Vehicles::const_reference inst) -> void {
// Push the script object on the stack
sq_pushobject(DefaultVM::Get(), inst.mObj.GetObject());
// Append the object at the back of the array
if (SQ_FAILED(sq_arrayappend(DefaultVM::Get(), -2)))
{
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)
{
@ -1855,10 +1781,6 @@ void Register_CVehicle(HSQUIRRELVM vm)
(_SC("Embark"), &CVehicle::Embark)
.Overload< bool (CVehicle::*)(CPlayer &, Int32, bool, bool) const >
(_SC("Embark"), &CVehicle::Embark)
// 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)