1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-02-21 20:27:13 +01: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

@ -2,7 +2,292 @@
#include "Base/Algo.hpp" #include "Base/Algo.hpp"
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
namespace SqMod { #include "Entity/Blip.hpp"
#include "Entity/Checkpoint.hpp"
#include "Entity/Keybind.hpp"
#include "Entity/Object.hpp"
#include "Entity/Pickup.hpp"
#include "Entity/Player.hpp"
#include "Entity/Vehicle.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
namespace Algo {
// ================================================================================================
void Register(HSQUIRRELVM vm)
{
Table fns(vm);
fns.Bind(_SC("Blip"), Table(vm)
.Func(_SC("WithID"), &Entity< CBlip >::FindByID)
.Func(_SC("IfTagEquals"), &Entity< CBlip >::FirstWhereTagEquals)
.Func(_SC("IfTagNotEquals"), &Entity< CBlip >::FirstWhereTagNotEquals)
.Func(_SC("IfTagBegins"), &Entity< CBlip >::FirstWhereTagBegins)
.Func(_SC("IfTagNotBegins"), &Entity< CBlip >::FirstWhereTagNotBegins)
.Func(_SC("IfTagEnds"), &Entity< CBlip >::FirstWhereTagEnds)
.Func(_SC("IfTagNotEnds"), &Entity< CBlip >::FirstWhereTagNotEnds)
.Func(_SC("IfTagContains"), &Entity< CBlip >::FirstWhereTagContains)
.Func(_SC("IfTagNotContains"), &Entity< CBlip >::FirstWhereTagNotContains)
);
fns.Bind(_SC("Checkpoint"), Table(vm)
.Func(_SC("WithID"), &Entity< CCheckpoint >::FindByID)
.Func(_SC("IfTagEquals"), &Entity< CCheckpoint >::FirstWhereTagEquals)
.Func(_SC("IfTagNotEquals"), &Entity< CCheckpoint >::FirstWhereTagNotEquals)
.Func(_SC("IfTagBegins"), &Entity< CCheckpoint >::FirstWhereTagBegins)
.Func(_SC("IfTagNotBegins"), &Entity< CCheckpoint >::FirstWhereTagNotBegins)
.Func(_SC("IfTagEnds"), &Entity< CCheckpoint >::FirstWhereTagEnds)
.Func(_SC("IfTagNotEnds"), &Entity< CCheckpoint >::FirstWhereTagNotEnds)
.Func(_SC("IfTagContains"), &Entity< CCheckpoint >::FirstWhereTagContains)
.Func(_SC("IfTagNotContains"), &Entity< CCheckpoint >::FirstWhereTagNotContains)
);
fns.Bind(_SC("Keybind"), Table(vm)
.Func(_SC("WithID"), &Entity< CKeybind >::FindByID)
.Func(_SC("IfTagEquals"), &Entity< CKeybind >::FirstWhereTagEquals)
.Func(_SC("IfTagNotEquals"), &Entity< CKeybind >::FirstWhereTagNotEquals)
.Func(_SC("IfTagBegins"), &Entity< CKeybind >::FirstWhereTagBegins)
.Func(_SC("IfTagNotBegins"), &Entity< CKeybind >::FirstWhereTagNotBegins)
.Func(_SC("IfTagEnds"), &Entity< CKeybind >::FirstWhereTagEnds)
.Func(_SC("IfTagNotEnds"), &Entity< CKeybind >::FirstWhereTagNotEnds)
.Func(_SC("IfTagContains"), &Entity< CKeybind >::FirstWhereTagContains)
.Func(_SC("IfTagNotContains"), &Entity< CKeybind >::FirstWhereTagNotContains)
);
fns.Bind(_SC("Object"), Table(vm)
.Func(_SC("WithID"), &Entity< CObject >::FindByID)
.Func(_SC("IfTagEquals"), &Entity< CObject >::FirstWhereTagEquals)
.Func(_SC("IfTagNotEquals"), &Entity< CObject >::FirstWhereTagNotEquals)
.Func(_SC("IfTagBegins"), &Entity< CObject >::FirstWhereTagBegins)
.Func(_SC("IfTagNotBegins"), &Entity< CObject >::FirstWhereTagNotBegins)
.Func(_SC("IfTagEnds"), &Entity< CObject >::FirstWhereTagEnds)
.Func(_SC("IfTagNotEnds"), &Entity< CObject >::FirstWhereTagNotEnds)
.Func(_SC("IfTagContains"), &Entity< CObject >::FirstWhereTagContains)
.Func(_SC("IfTagNotContains"), &Entity< CObject >::FirstWhereTagNotContains)
);
fns.Bind(_SC("Pickup"), Table(vm)
.Func(_SC("WithID"), &Entity< CPickup >::FindByID)
.Func(_SC("IfTagEquals"), &Entity< CPickup >::FirstWhereTagEquals)
.Func(_SC("IfTagNotEquals"), &Entity< CPickup >::FirstWhereTagNotEquals)
.Func(_SC("IfTagBegins"), &Entity< CPickup >::FirstWhereTagBegins)
.Func(_SC("IfTagNotBegins"), &Entity< CPickup >::FirstWhereTagNotBegins)
.Func(_SC("IfTagEnds"), &Entity< CPickup >::FirstWhereTagEnds)
.Func(_SC("IfTagNotEnds"), &Entity< CPickup >::FirstWhereTagNotEnds)
.Func(_SC("IfTagContains"), &Entity< CPickup >::FirstWhereTagContains)
.Func(_SC("IfTagNotContains"), &Entity< CPickup >::FirstWhereTagNotContains)
);
fns.Bind(_SC("Player"), Table(vm)
.Func(_SC("WithID"), &Entity< CPlayer >::FindByID)
.Func(_SC("IfTagEquals"), &Entity< CPlayer >::FirstWhereTagEquals)
.Func(_SC("IfTagNotEquals"), &Entity< CPlayer >::FirstWhereTagNotEquals)
.Func(_SC("IfTagBegins"), &Entity< CPlayer >::FirstWhereTagBegins)
.Func(_SC("IfTagNotBegins"), &Entity< CPlayer >::FirstWhereTagNotBegins)
.Func(_SC("IfTagEnds"), &Entity< CPlayer >::FirstWhereTagEnds)
.Func(_SC("IfTagNotEnds"), &Entity< CPlayer >::FirstWhereTagNotEnds)
.Func(_SC("IfTagContains"), &Entity< CPlayer >::FirstWhereTagContains)
.Func(_SC("IfTagNotContains"), &Entity< CPlayer >::FirstWhereTagNotContains)
);
fns.Bind(_SC("Vehicle"), Table(vm)
.Func(_SC("WithID"), &Entity< CVehicle >::FindByID)
.Func(_SC("IfTagEquals"), &Entity< CVehicle >::FirstWhereTagEquals)
.Func(_SC("IfTagNotEquals"), &Entity< CVehicle >::FirstWhereTagNotEquals)
.Func(_SC("IfTagBegins"), &Entity< CVehicle >::FirstWhereTagBegins)
.Func(_SC("IfTagNotBegins"), &Entity< CVehicle >::FirstWhereTagNotBegins)
.Func(_SC("IfTagEnds"), &Entity< CVehicle >::FirstWhereTagEnds)
.Func(_SC("IfTagNotEnds"), &Entity< CVehicle >::FirstWhereTagNotEnds)
.Func(_SC("IfTagContains"), &Entity< CVehicle >::FirstWhereTagContains)
.Func(_SC("IfTagNotContains"), &Entity< CVehicle >::FirstWhereTagNotContains)
);
RootTable(vm).Bind(_SC("SqFind"), fns);
Table cns(vm);
cns.Bind(_SC("Blip"), Table(vm)
.Func(_SC("IfActive"), &Entity< CBlip >::AllActive)
.Func(_SC("IfTagEquals"), &Entity< CBlip >::AllWhereTagEquals)
.Func(_SC("IfTagNotEquals"), &Entity< CBlip >::AllWhereTagNotEquals)
.Func(_SC("IfTagBegins"), &Entity< CBlip >::AllWhereTagBegins)
.Func(_SC("IfTagNotBegins"), &Entity< CBlip >::AllWhereTagNotBegins)
.Func(_SC("IfTagEnds"), &Entity< CBlip >::AllWhereTagEnds)
.Func(_SC("IfTagNotEnds"), &Entity< CBlip >::AllWhereTagNotEnds)
.Func(_SC("IfTagContains"), &Entity< CBlip >::AllWhereTagContains)
.Func(_SC("IfTagNotContains"), &Entity< CBlip >::AllWhereTagNotContains)
);
cns.Bind(_SC("Checkpoint"), Table(vm)
.Func(_SC("IfActive"), &Entity< CCheckpoint >::AllActive)
.Func(_SC("IfTagEquals"), &Entity< CCheckpoint >::AllWhereTagEquals)
.Func(_SC("IfTagNotEquals"), &Entity< CCheckpoint >::AllWhereTagNotEquals)
.Func(_SC("IfTagBegins"), &Entity< CCheckpoint >::AllWhereTagBegins)
.Func(_SC("IfTagNotBegins"), &Entity< CCheckpoint >::AllWhereTagNotBegins)
.Func(_SC("IfTagEnds"), &Entity< CCheckpoint >::AllWhereTagEnds)
.Func(_SC("IfTagNotEnds"), &Entity< CCheckpoint >::AllWhereTagNotEnds)
.Func(_SC("IfTagContains"), &Entity< CCheckpoint >::AllWhereTagContains)
.Func(_SC("IfTagNotContains"), &Entity< CCheckpoint >::AllWhereTagNotContains)
);
cns.Bind(_SC("Keybind"), Table(vm)
.Func(_SC("IfActive"), &Entity< CKeybind >::AllActive)
.Func(_SC("IfTagEquals"), &Entity< CKeybind >::AllWhereTagEquals)
.Func(_SC("IfTagNotEquals"), &Entity< CKeybind >::AllWhereTagNotEquals)
.Func(_SC("IfTagBegins"), &Entity< CKeybind >::AllWhereTagBegins)
.Func(_SC("IfTagNotBegins"), &Entity< CKeybind >::AllWhereTagNotBegins)
.Func(_SC("IfTagEnds"), &Entity< CKeybind >::AllWhereTagEnds)
.Func(_SC("IfTagNotEnds"), &Entity< CKeybind >::AllWhereTagNotEnds)
.Func(_SC("IfTagContains"), &Entity< CKeybind >::AllWhereTagContains)
.Func(_SC("IfTagNotContains"), &Entity< CKeybind >::AllWhereTagNotContains)
);
cns.Bind(_SC("Object"), Table(vm)
.Func(_SC("IfActive"), &Entity< CObject >::AllActive)
.Func(_SC("IfTagEquals"), &Entity< CObject >::AllWhereTagEquals)
.Func(_SC("IfTagNotEquals"), &Entity< CObject >::AllWhereTagNotEquals)
.Func(_SC("IfTagBegins"), &Entity< CObject >::AllWhereTagBegins)
.Func(_SC("IfTagNotBegins"), &Entity< CObject >::AllWhereTagNotBegins)
.Func(_SC("IfTagEnds"), &Entity< CObject >::AllWhereTagEnds)
.Func(_SC("IfTagNotEnds"), &Entity< CObject >::AllWhereTagNotEnds)
.Func(_SC("IfTagContains"), &Entity< CObject >::AllWhereTagContains)
.Func(_SC("IfTagNotContains"), &Entity< CObject >::AllWhereTagNotContains)
);
cns.Bind(_SC("Pickup"), Table(vm)
.Func(_SC("IfActive"), &Entity< CPickup >::AllActive)
.Func(_SC("IfTagEquals"), &Entity< CPickup >::AllWhereTagEquals)
.Func(_SC("IfTagNotEquals"), &Entity< CPickup >::AllWhereTagNotEquals)
.Func(_SC("IfTagBegins"), &Entity< CPickup >::AllWhereTagBegins)
.Func(_SC("IfTagNotBegins"), &Entity< CPickup >::AllWhereTagNotBegins)
.Func(_SC("IfTagEnds"), &Entity< CPickup >::AllWhereTagEnds)
.Func(_SC("IfTagNotEnds"), &Entity< CPickup >::AllWhereTagNotEnds)
.Func(_SC("IfTagContains"), &Entity< CPickup >::AllWhereTagContains)
.Func(_SC("IfTagNotContains"), &Entity< CPickup >::AllWhereTagNotContains)
);
cns.Bind(_SC("Player"), Table(vm)
.Func(_SC("IfActive"), &Entity< CPlayer >::AllActive)
.Func(_SC("IfTagEquals"), &Entity< CPlayer >::AllWhereTagEquals)
.Func(_SC("IfTagNotEquals"), &Entity< CPlayer >::AllWhereTagNotEquals)
.Func(_SC("IfTagBegins"), &Entity< CPlayer >::AllWhereTagBegins)
.Func(_SC("IfTagNotBegins"), &Entity< CPlayer >::AllWhereTagNotBegins)
.Func(_SC("IfTagEnds"), &Entity< CPlayer >::AllWhereTagEnds)
.Func(_SC("IfTagNotEnds"), &Entity< CPlayer >::AllWhereTagNotEnds)
.Func(_SC("IfTagContains"), &Entity< CPlayer >::AllWhereTagContains)
.Func(_SC("IfTagNotContains"), &Entity< CPlayer >::AllWhereTagNotContains)
);
cns.Bind(_SC("Vehicle"), Table(vm)
.Func(_SC("IfActive"), &Entity< CVehicle >::AllActive)
.Func(_SC("IfTagEquals"), &Entity< CVehicle >::AllWhereTagEquals)
.Func(_SC("IfTagNotEquals"), &Entity< CVehicle >::AllWhereTagNotEquals)
.Func(_SC("IfTagBegins"), &Entity< CVehicle >::AllWhereTagBegins)
.Func(_SC("IfTagNotBegins"), &Entity< CVehicle >::AllWhereTagNotBegins)
.Func(_SC("IfTagEnds"), &Entity< CVehicle >::AllWhereTagEnds)
.Func(_SC("IfTagNotEnds"), &Entity< CVehicle >::AllWhereTagNotEnds)
.Func(_SC("IfTagContains"), &Entity< CVehicle >::AllWhereTagContains)
.Func(_SC("IfTagNotContains"), &Entity< CVehicle >::AllWhereTagNotContains)
);
RootTable(vm).Bind(_SC("SqCollect"), cns);
Table ens(vm);
ens.Bind(_SC("Blip"), Table(vm)
.Func(_SC("IfActive"), &Entity< CBlip >::EachActive)
.Func(_SC("IfTagEquals"), &Entity< CBlip >::EachWhereTagEquals)
.Func(_SC("IfTagNotEquals"), &Entity< CBlip >::EachWhereTagNotEquals)
.Func(_SC("IfTagBegins"), &Entity< CBlip >::EachWhereTagBegins)
.Func(_SC("IfTagNotBegins"), &Entity< CBlip >::EachWhereTagNotBegins)
.Func(_SC("IfTagEnds"), &Entity< CBlip >::EachWhereTagEnds)
.Func(_SC("IfTagNotEnds"), &Entity< CBlip >::EachWhereTagNotEnds)
.Func(_SC("IfTagContains"), &Entity< CBlip >::EachWhereTagContains)
.Func(_SC("IfTagNotContains"), &Entity< CBlip >::EachWhereTagNotContains)
);
ens.Bind(_SC("Checkpoint"), Table(vm)
.Func(_SC("IfActive"), &Entity< CCheckpoint >::EachActive)
.Func(_SC("IfTagEquals"), &Entity< CCheckpoint >::EachWhereTagEquals)
.Func(_SC("IfTagNotEquals"), &Entity< CCheckpoint >::EachWhereTagNotEquals)
.Func(_SC("IfTagBegins"), &Entity< CCheckpoint >::EachWhereTagBegins)
.Func(_SC("IfTagNotBegins"), &Entity< CCheckpoint >::EachWhereTagNotBegins)
.Func(_SC("IfTagEnds"), &Entity< CCheckpoint >::EachWhereTagEnds)
.Func(_SC("IfTagNotEnds"), &Entity< CCheckpoint >::EachWhereTagNotEnds)
.Func(_SC("IfTagContains"), &Entity< CCheckpoint >::EachWhereTagContains)
.Func(_SC("IfTagNotContains"), &Entity< CCheckpoint >::EachWhereTagNotContains)
);
ens.Bind(_SC("Keybind"), Table(vm)
.Func(_SC("IfActive"), &Entity< CKeybind >::EachActive)
.Func(_SC("IfTagEquals"), &Entity< CKeybind >::EachWhereTagEquals)
.Func(_SC("IfTagNotEquals"), &Entity< CKeybind >::EachWhereTagNotEquals)
.Func(_SC("IfTagBegins"), &Entity< CKeybind >::EachWhereTagBegins)
.Func(_SC("IfTagNotBegins"), &Entity< CKeybind >::EachWhereTagNotBegins)
.Func(_SC("IfTagEnds"), &Entity< CKeybind >::EachWhereTagEnds)
.Func(_SC("IfTagNotEnds"), &Entity< CKeybind >::EachWhereTagNotEnds)
.Func(_SC("IfTagContains"), &Entity< CKeybind >::EachWhereTagContains)
.Func(_SC("IfTagNotContains"), &Entity< CKeybind >::EachWhereTagNotContains)
);
ens.Bind(_SC("Object"), Table(vm)
.Func(_SC("IfActive"), &Entity< CObject >::EachActive)
.Func(_SC("IfTagEquals"), &Entity< CObject >::EachWhereTagEquals)
.Func(_SC("IfTagNotEquals"), &Entity< CObject >::EachWhereTagNotEquals)
.Func(_SC("IfTagBegins"), &Entity< CObject >::EachWhereTagBegins)
.Func(_SC("IfTagNotBegins"), &Entity< CObject >::EachWhereTagNotBegins)
.Func(_SC("IfTagEnds"), &Entity< CObject >::EachWhereTagEnds)
.Func(_SC("IfTagNotEnds"), &Entity< CObject >::EachWhereTagNotEnds)
.Func(_SC("IfTagContains"), &Entity< CObject >::EachWhereTagContains)
.Func(_SC("IfTagNotContains"), &Entity< CObject >::EachWhereTagNotContains)
);
ens.Bind(_SC("Pickup"), Table(vm)
.Func(_SC("IfActive"), &Entity< CPickup >::EachActive)
.Func(_SC("IfTagEquals"), &Entity< CPickup >::EachWhereTagEquals)
.Func(_SC("IfTagNotEquals"), &Entity< CPickup >::EachWhereTagNotEquals)
.Func(_SC("IfTagBegins"), &Entity< CPickup >::EachWhereTagBegins)
.Func(_SC("IfTagNotBegins"), &Entity< CPickup >::EachWhereTagNotBegins)
.Func(_SC("IfTagEnds"), &Entity< CPickup >::EachWhereTagEnds)
.Func(_SC("IfTagNotEnds"), &Entity< CPickup >::EachWhereTagNotEnds)
.Func(_SC("IfTagContains"), &Entity< CPickup >::EachWhereTagContains)
.Func(_SC("IfTagNotContains"), &Entity< CPickup >::EachWhereTagNotContains)
);
ens.Bind(_SC("Player"), Table(vm)
.Func(_SC("IfActive"), &Entity< CPlayer >::EachActive)
.Func(_SC("IfTagEquals"), &Entity< CPlayer >::EachWhereTagEquals)
.Func(_SC("IfTagNotEquals"), &Entity< CPlayer >::EachWhereTagNotEquals)
.Func(_SC("IfTagBegins"), &Entity< CPlayer >::EachWhereTagBegins)
.Func(_SC("IfTagNotBegins"), &Entity< CPlayer >::EachWhereTagNotBegins)
.Func(_SC("IfTagEnds"), &Entity< CPlayer >::EachWhereTagEnds)
.Func(_SC("IfTagNotEnds"), &Entity< CPlayer >::EachWhereTagNotEnds)
.Func(_SC("IfTagContains"), &Entity< CPlayer >::EachWhereTagContains)
.Func(_SC("IfTagNotContains"), &Entity< CPlayer >::EachWhereTagNotContains)
);
ens.Bind(_SC("Vehicle"), Table(vm)
.Func(_SC("IfActive"), &Entity< CVehicle >::EachActive)
.Func(_SC("IfTagEquals"), &Entity< CVehicle >::EachWhereTagEquals)
.Func(_SC("IfTagNotEquals"), &Entity< CVehicle >::EachWhereTagNotEquals)
.Func(_SC("IfTagBegins"), &Entity< CVehicle >::EachWhereTagBegins)
.Func(_SC("IfTagNotBegins"), &Entity< CVehicle >::EachWhereTagNotBegins)
.Func(_SC("IfTagEnds"), &Entity< CVehicle >::EachWhereTagEnds)
.Func(_SC("IfTagNotEnds"), &Entity< CVehicle >::EachWhereTagNotEnds)
.Func(_SC("IfTagContains"), &Entity< CVehicle >::EachWhereTagContains)
.Func(_SC("IfTagNotContains"), &Entity< CVehicle >::EachWhereTagNotContains)
);
RootTable(vm).Bind(_SC("SqForeach"), ens);
}
} // Namespace:: Algo
// ================================================================================================
void Register_Algo(HSQUIRRELVM vm)
{
Algo::Register(vm);
}
} // Namespace:: SqMod } // Namespace:: SqMod

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,5 @@
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
#include "Entity/Blip.hpp" #include "Entity/Blip.hpp"
#include "Base/Algo.hpp"
#include "Core.hpp" #include "Core.hpp"
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -287,100 +286,6 @@ static Object & Blip_Create(Int32 index, Int32 world, const Vector3 & pos, Int32
header, payload); 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) void Register_CBlip(HSQUIRRELVM vm)
{ {
@ -418,11 +323,6 @@ void Register_CBlip(HSQUIRRELVM vm)
.Prop(_SC("Green"), &CBlip::GetColorG) .Prop(_SC("Green"), &CBlip::GetColorG)
.Prop(_SC("Blue"), &CBlip::GetColorB) .Prop(_SC("Blue"), &CBlip::GetColorB)
.Prop(_SC("Alpha"), &CBlip::GetColorA) .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 // Static Overloads
.StaticOverload< Object & (*)(Int32, Float32, Float32, Float32, Int32, Uint8, Uint8, Uint8, Uint8, Int32) > .StaticOverload< Object & (*)(Int32, Float32, Float32, Float32, Int32, Uint8, Uint8, Uint8, Uint8, Int32) >
(_SC("CreateEx"), &Blip_CreateEx) (_SC("CreateEx"), &Blip_CreateEx)

View File

@ -1,7 +1,6 @@
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
#include "Entity/Checkpoint.hpp" #include "Entity/Checkpoint.hpp"
#include "Entity/Player.hpp" #include "Entity/Player.hpp"
#include "Base/Algo.hpp"
#include "Base/Color4.hpp" #include "Base/Color4.hpp"
#include "Base/Vector3.hpp" #include "Base/Vector3.hpp"
#include "Core.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); 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) void Register_CCheckpoint(HSQUIRRELVM vm)
{ {
@ -603,10 +529,6 @@ void Register_CCheckpoint(HSQUIRRELVM vm)
(_SC("SetColor"), &CCheckpoint::SetColorEx) (_SC("SetColor"), &CCheckpoint::SetColorEx)
.Overload< void (CCheckpoint::*)(Uint8, Uint8, Uint8, Uint8) const > .Overload< void (CCheckpoint::*)(Uint8, Uint8, Uint8, Uint8) const >
(_SC("SetColor"), &CCheckpoint::SetColorEx) (_SC("SetColor"), &CCheckpoint::SetColorEx)
// Static Functions
.StaticFunc(_SC("FindByID"), &Checkpoint_FindByID)
.StaticFunc(_SC("FindByTag"), &Checkpoint_FindByTag)
.StaticFunc(_SC("FindActive"), &Checkpoint_FindActive)
// Static Overloads // Static Overloads
.StaticOverload< Object & (*)(CPlayer &, Int32, bool, Float32, Float32, Float32, Uint8, Uint8, Uint8, Uint8, Float32) > .StaticOverload< Object & (*)(CPlayer &, Int32, bool, Float32, Float32, Float32, Uint8, Uint8, Uint8, Uint8, Float32) >
(_SC("CreateEx"), &Checkpoint_CreateEx) (_SC("CreateEx"), &Checkpoint_CreateEx)

View File

@ -1,6 +1,5 @@
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
#include "Entity/Keybind.hpp" #include "Entity/Keybind.hpp"
#include "Base/Algo.hpp"
#include "Core.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); 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() static SQInteger Keybind_UnusedSlot()
{ {
@ -287,9 +213,6 @@ void Register_CKeybind(HSQUIRRELVM vm)
.Prop(_SC("Third"), &CKeybind::GetThird) .Prop(_SC("Third"), &CKeybind::GetThird)
.Prop(_SC("Release"), &CKeybind::IsRelease) .Prop(_SC("Release"), &CKeybind::IsRelease)
// Static Functions // Static Functions
.StaticFunc(_SC("FindByID"), &Keybind_FindByID)
.StaticFunc(_SC("FindByTag"), &Keybind_FindByTag)
.StaticFunc(_SC("FindActive"), &Keybind_FindActive)
.StaticFunc(_SC("UnusedSlot"), &Keybind_UnusedSlot) .StaticFunc(_SC("UnusedSlot"), &Keybind_UnusedSlot)
// Static Overloads // Static Overloads
.StaticOverload< Object & (*)(Int32, bool, Int32, Int32, Int32) > .StaticOverload< Object & (*)(Int32, bool, Int32, Int32, Int32) >

View File

@ -1,7 +1,6 @@
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
#include "Entity/Object.hpp" #include "Entity/Object.hpp"
#include "Entity/Player.hpp" #include "Entity/Player.hpp"
#include "Base/Algo.hpp"
#include "Base/Quaternion.hpp" #include "Base/Quaternion.hpp"
#include "Base/Vector3.hpp" #include "Base/Vector3.hpp"
#include "Core.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); 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) void Register_CObject(HSQUIRRELVM vm)
{ {
@ -980,10 +908,6 @@ void Register_CObject(HSQUIRRELVM vm)
(_SC("RotateByEuler"), &CObject::RotateByEuler) (_SC("RotateByEuler"), &CObject::RotateByEuler)
.Overload< void (CObject::*)(Float32, Float32, Float32, Uint32) const > .Overload< void (CObject::*)(Float32, Float32, Float32, Uint32) const >
(_SC("RotateByEuler"), &CObject::RotateByEulerEx) (_SC("RotateByEuler"), &CObject::RotateByEulerEx)
// Static Functions
.StaticFunc(_SC("FindByID"), &Object_FindByID)
.StaticFunc(_SC("FindByTag"), &Object_FindByTag)
.StaticFunc(_SC("FindActive"), &Object_FindActive)
// Static Overloads // Static Overloads
.StaticOverload< Object & (*)(Int32, Int32, Float32, Float32, Float32, Int32) > .StaticOverload< Object & (*)(Int32, Int32, Float32, Float32, Float32, Int32) >
(_SC("CreateEx"), &Object_CreateEx) (_SC("CreateEx"), &Object_CreateEx)

View File

@ -1,7 +1,6 @@
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
#include "Entity/Pickup.hpp" #include "Entity/Pickup.hpp"
#include "Entity/Player.hpp" #include "Entity/Player.hpp"
#include "Base/Algo.hpp"
#include "Base/Vector3.hpp" #include "Base/Vector3.hpp"
#include "Core.hpp" #include "Core.hpp"
@ -368,79 +367,6 @@ static Object & Pickup_Create(Int32 model, Int32 world, Int32 quantity, const Ve
header, payload); 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) void Register_CPickup(HSQUIRRELVM vm)
{ {
@ -482,10 +408,6 @@ void Register_CPickup(HSQUIRRELVM vm)
.Func(_SC("Refresh"), &CPickup::Refresh) .Func(_SC("Refresh"), &CPickup::Refresh)
.Func(_SC("SetPos"), &CPickup::SetPositionEx) .Func(_SC("SetPos"), &CPickup::SetPositionEx)
.Func(_SC("SetPosition"), &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 // Static Overloads
.StaticOverload< Object & (*)(Int32, Int32, Int32, Float32, Float32, Float32, Int32, bool) > .StaticOverload< Object & (*)(Int32, Int32, Int32, Float32, Float32, Float32, Int32, bool) >
(_SC("CreateEx"), &Pickup_CreateEx) (_SC("CreateEx"), &Pickup_CreateEx)

View File

@ -1,7 +1,6 @@
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
#include "Entity/Player.hpp" #include "Entity/Player.hpp"
#include "Entity/Vehicle.hpp" #include "Entity/Vehicle.hpp"
#include "Base/Algo.hpp"
#include "Base/Color3.hpp" #include "Base/Color3.hpp"
#include "Base/Color4.hpp" #include "Base/Color4.hpp"
#include "Base/Vector3.hpp" #include "Base/Vector3.hpp"
@ -2062,110 +2061,6 @@ SQInteger CPlayer::AnnounceEx(HSQUIRRELVM vm)
return 0; 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) void Register_CPlayer(HSQUIRRELVM vm)
{ {
@ -2334,11 +2229,6 @@ void Register_CPlayer(HSQUIRRELVM vm)
.SquirrelFunc(_SC("AnnounceEx"), &CPlayer::AnnounceEx) .SquirrelFunc(_SC("AnnounceEx"), &CPlayer::AnnounceEx)
.SquirrelFunc(_SC("Text"), &CPlayer::Announce) .SquirrelFunc(_SC("Text"), &CPlayer::Announce)
.SquirrelFunc(_SC("TextEx"), &CPlayer::AnnounceEx) .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/Vehicle.hpp"
#include "Entity/Player.hpp" #include "Entity/Player.hpp"
#include "Base/Algo.hpp"
#include "Base/Quaternion.hpp" #include "Base/Quaternion.hpp"
#include "Base/Vector2.hpp" #include "Base/Vector2.hpp"
#include "Base/Vector3.hpp" #include "Base/Vector3.hpp"
@ -1625,79 +1624,6 @@ static Object & Vehicle_Create(Int32 model, Int32 world, const Vector3 & pos, Fl
header, payload); 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) void Register_CVehicle(HSQUIRRELVM vm)
{ {
@ -1855,10 +1781,6 @@ void Register_CVehicle(HSQUIRRELVM vm)
(_SC("Embark"), &CVehicle::Embark) (_SC("Embark"), &CVehicle::Embark)
.Overload< bool (CVehicle::*)(CPlayer &, Int32, bool, bool) const > .Overload< bool (CVehicle::*)(CPlayer &, Int32, bool, bool) const >
(_SC("Embark"), &CVehicle::Embark) (_SC("Embark"), &CVehicle::Embark)
// Static Functions
.StaticFunc(_SC("FindByID"), &Vehicle_FindByID)
.StaticFunc(_SC("FindByTag"), &Vehicle_FindByTag)
.StaticFunc(_SC("FindActive"), &Vehicle_FindActive)
// Static Overloads // Static Overloads
.StaticOverload< Object & (*)(Int32, Int32, Float32, Float32, Float32, Float32, Int32, Int32) > .StaticOverload< Object & (*)(Int32, Int32, Float32, Float32, Float32, Float32, Int32, Int32) >
(_SC("CreateEx"), &Vehicle_CreateEx) (_SC("CreateEx"), &Vehicle_CreateEx)