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

Migrated the host module to C++ exceptions as well.

Also enabled the latest C++ revision in the project.
Replaced the Random library with the one provided by C++11.
Implemented a simple AES256 encryption class.
Various other fixes and improvements.
This commit is contained in:
Sandu Liviu Catalin
2016-03-10 05:57:13 +02:00
parent 3162221e7f
commit 70e5f0ba21
124 changed files with 14873 additions and 14062 deletions

View File

@ -6,15 +6,20 @@
namespace SqMod {
// ------------------------------------------------------------------------------------------------
SQChar CBlip::s_StrID[SQMOD_BLIP_POOL][8];
const Int32 CBlip::Max = SQMOD_BLIP_POOL;
// ------------------------------------------------------------------------------------------------
const Int32 CBlip::Max = SQMOD_BLIP_POOL;
SQInteger CBlip::Typename(HSQUIRRELVM vm)
{
static SQChar name[] = _SC("SqBlip");
sq_pushstring(vm, name, sizeof(name));
return 1;
}
// ------------------------------------------------------------------------------------------------
CBlip::CBlip(Int32 id)
: m_ID(VALID_ENTITYGETEX(id, SQMOD_BLIP_POOL))
, m_Tag(VALID_ENTITY(m_ID) ? s_StrID[m_ID] : _SC("-1"))
, m_Tag(ToStrF("%d", id))
{
/* ... */
}
@ -36,153 +41,183 @@ Int32 CBlip::Cmp(const CBlip & o) const
return -1;
}
CSStr CBlip::ToString() const
// ------------------------------------------------------------------------------------------------
const String & CBlip::ToString() const
{
return VALID_ENTITYEX(m_ID, SQMOD_BLIP_POOL) ? s_StrID[m_ID] : _SC("-1");
return m_Tag;
}
// ------------------------------------------------------------------------------------------------
CSStr CBlip::GetTag() const
const String & CBlip::GetTag() const
{
return m_Tag.c_str();
return m_Tag;
}
// ------------------------------------------------------------------------------------------------
void CBlip::SetTag(CSStr tag)
{
m_Tag.assign(tag);
}
// ------------------------------------------------------------------------------------------------
Object & CBlip::GetData()
{
if (Validate())
return m_Data;
return NullObject();
// Validate the managed identifier
Validate();
// Return the requested information
return m_Data;
}
// ------------------------------------------------------------------------------------------------
void CBlip::SetData(Object & data)
{
if (Validate())
m_Data = data;
// Validate the managed identifier
Validate();
// Apply the specified value
m_Data = data;
}
// ------------------------------------------------------------------------------------------------
bool CBlip::Destroy(Int32 header, Object & payload)
{
// Validate the managed identifier
Validate();
// Perform the requested operation
return _Core->DelBlip(m_ID, header, payload);
}
// ------------------------------------------------------------------------------------------------
bool CBlip::BindEvent(Int32 evid, Object & env, Function & func) const
void CBlip::BindEvent(Int32 evid, Object & env, Function & func) const
{
if (!Validate())
return false;
// Validate the managed identifier
Validate();
// Obtain the function instance called for this event
Function & event = _Core->GetBlipEvent(m_ID, evid);
// Is the specified callback function null?
if (func.IsNull())
event.Release();
event.Release(); // Then release the current callback
// Assign the specified environment and function
else
event = Function(env.GetVM(), env, func.GetFunc());
return true;
}
// ------------------------------------------------------------------------------------------------
Int32 CBlip::GetWorld() const
{
if (Validate())
return _Core->GetBlip(m_ID).mWorld;
return -1;
// Validate the managed identifier
Validate();
// Return the requested information
return _Core->GetBlip(m_ID).mWorld;
}
// ------------------------------------------------------------------------------------------------
Int32 CBlip::GetScale() const
{
if (Validate())
return _Core->GetBlip(m_ID).mScale;
return -1;
// Validate the managed identifier
Validate();
// Return the requested information
return _Core->GetBlip(m_ID).mScale;
}
// ------------------------------------------------------------------------------------------------
const Vector3 & CBlip::GetPosition() const
{
if (Validate())
return _Core->GetBlip(m_ID).mPosition;
return Vector3::NIL;
// Validate the managed identifier
Validate();
// Return the requested information
return _Core->GetBlip(m_ID).mPosition;
}
// ------------------------------------------------------------------------------------------------
const Color4 & CBlip::GetColor() const
{
if (Validate())
return _Core->GetBlip(m_ID).mColor;
return Color4::NIL;
// Validate the managed identifier
Validate();
// Return the requested information
return _Core->GetBlip(m_ID).mColor;
}
// ------------------------------------------------------------------------------------------------
Int32 CBlip::GetSprID() const
{
if (Validate())
return _Core->GetBlip(m_ID).mSprID;
return -1;
// Validate the managed identifier
Validate();
// Return the requested information
return _Core->GetBlip(m_ID).mSprID;
}
// ------------------------------------------------------------------------------------------------
Float32 CBlip::GetPosX() const
{
if (Validate())
return _Core->GetBlip(m_ID).mPosition.x;
return 0;
// Validate the managed identifier
Validate();
// Return the requested information
return _Core->GetBlip(m_ID).mPosition.x;
}
// ------------------------------------------------------------------------------------------------
Float32 CBlip::GetPosY() const
{
if (Validate())
return _Core->GetBlip(m_ID).mPosition.y;
return 0;
// Validate the managed identifier
Validate();
// Return the requested information
return _Core->GetBlip(m_ID).mPosition.y;
}
// ------------------------------------------------------------------------------------------------
Float32 CBlip::GetPosZ() const
{
if (Validate())
return _Core->GetBlip(m_ID).mPosition.z;
return 0;
// Validate the managed identifier
Validate();
// Return the requested information
return _Core->GetBlip(m_ID).mPosition.z;
}
// ------------------------------------------------------------------------------------------------
Int32 CBlip::GetColorR() const
{
if (Validate())
return _Core->GetBlip(m_ID).mColor.r;
return 0;
}
Int32 CBlip::GetColorG() const
{
if (Validate())
return _Core->GetBlip(m_ID).mColor.g;
return 0;
}
Int32 CBlip::GetColorB() const
{
if (Validate())
return _Core->GetBlip(m_ID).mColor.b;
return 0;
}
Int32 CBlip::GetColorA() const
{
if (Validate())
return _Core->GetBlip(m_ID).mColor.a;
return 0;
// Validate the managed identifier
Validate();
// Return the requested information
return _Core->GetBlip(m_ID).mColor.r;
}
// ------------------------------------------------------------------------------------------------
static Object & CreateBlipEx(Int32 world, Float32 x, Float32 y, Float32 z, Int32 scale,
Int32 CBlip::GetColorG() const
{
// Validate the managed identifier
Validate();
// Return the requested information
return _Core->GetBlip(m_ID).mColor.g;
}
// ------------------------------------------------------------------------------------------------
Int32 CBlip::GetColorB() const
{
// Validate the managed identifier
Validate();
// Return the requested information
return _Core->GetBlip(m_ID).mColor.b;
}
// ------------------------------------------------------------------------------------------------
Int32 CBlip::GetColorA() const
{
// Validate the managed identifier
Validate();
// Return the requested information
return _Core->GetBlip(m_ID).mColor.a;
}
// ------------------------------------------------------------------------------------------------
static Object & Blip_CreateEx(Int32 world, Float32 x, Float32 y, Float32 z, Int32 scale,
Uint8 r, Uint8 g, Uint8 b, Uint8 a, Int32 sprid)
{
return _Core->NewBlip(-1, world, x, y, z, scale, SQMOD_PACK_RGBA(r, g, b, a), sprid,
SQMOD_CREATE_DEFAULT, NullObject());
}
static Object & CreateBlipEx(Int32 world, Float32 x, Float32 y, Float32 z, Int32 scale,
static Object & Blip_CreateEx(Int32 world, Float32 x, Float32 y, Float32 z, Int32 scale,
Uint8 r, Uint8 g, Uint8 b, Uint8 a, Int32 sprid,
Int32 header, Object & payload)
{
@ -191,14 +226,14 @@ static Object & CreateBlipEx(Int32 world, Float32 x, Float32 y, Float32 z, Int32
}
// ------------------------------------------------------------------------------------------------
static Object & CreateBlipEx(Int32 index, Int32 world, Float32 x, Float32 y, Float32 z,
static Object & Blip_CreateEx(Int32 index, Int32 world, Float32 x, Float32 y, Float32 z,
Int32 scale, Uint8 r, Uint8 g, Uint8 b, Uint8 a, Int32 sprid)
{
return _Core->NewBlip(index, world, x, y, z, scale, SQMOD_PACK_RGBA(r, g, b, a), sprid,
SQMOD_CREATE_DEFAULT, NullObject());
}
static Object & CreateBlipEx(Int32 index, Int32 world, Float32 x, Float32 y, Float32 z, Int32 scale,
static Object & Blip_CreateEx(Int32 index, Int32 world, Float32 x, Float32 y, Float32 z, Int32 scale,
Uint8 r, Uint8 g, Uint8 b, Uint8 a, Int32 sprid,
Int32 header, Object & payload)
{
@ -207,14 +242,14 @@ static Object & CreateBlipEx(Int32 index, Int32 world, Float32 x, Float32 y, Flo
}
// ------------------------------------------------------------------------------------------------
static Object & CreateBlip(Int32 world, const Vector3 & pos, Int32 scale, const Color4 & color,
static Object & Blip_Create(Int32 world, const Vector3 & pos, Int32 scale, const Color4 & color,
Int32 sprid)
{
return _Core->NewBlip(-1, world, pos.x, pos.y, pos.z, scale, color.GetRGBA(), sprid,
SQMOD_CREATE_DEFAULT, NullObject());
}
static Object & CreateBlip(Int32 world, const Vector3 & pos, Int32 scale, const Color4 & color,
static Object & Blip_Create(Int32 world, const Vector3 & pos, Int32 scale, const Color4 & color,
Int32 sprid, Int32 header, Object & payload)
{
return _Core->NewBlip(-1, world, pos.x, pos.y, pos.z, scale, color.GetRGBA(), sprid,
@ -222,41 +257,82 @@ static Object & CreateBlip(Int32 world, const Vector3 & pos, Int32 scale, const
}
// ------------------------------------------------------------------------------------------------
static Object & CreateBlip(Int32 index, Int32 world, const Vector3 & pos, Int32 scale,
static Object & Blip_Create(Int32 index, Int32 world, const Vector3 & pos, Int32 scale,
const Color4 & color, Int32 sprid)
{
return _Core->NewBlip(index, world, pos.x, pos.y, pos.z, scale, color.GetRGBA(), sprid,
SQMOD_CREATE_DEFAULT, NullObject());
}
static Object & CreateBlip(Int32 index, Int32 world, const Vector3 & pos, Int32 scale,
static Object & Blip_Create(Int32 index, Int32 world, const Vector3 & pos, Int32 scale,
const Color4 & color, Int32 sprid, Int32 header, Object & payload)
{
return _Core->NewBlip(index, world, pos.x, pos.y, pos.z, scale, color.GetRGBA(), sprid,
header, payload);
}
// ------------------------------------------------------------------------------------------------
static const Object & Blip_FindByID(Int32 id)
{
// Perform a range check on the specified identifier
if (INVALID_ENTITYEX(id, SQMOD_BLIP_POOL))
SqThrowF("The specified blip identifier is invalid: %d", id);
// Obtain the ends of the entity pool
Core::Blips::const_iterator itr = _Core->GetBlips().cbegin();
Core::Blips::const_iterator end = _Core->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)
SqThrowF("The specified blip tag is invalid: null/empty");
// Obtain the ends of the entity pool
Core::Blips::const_iterator itr = _Core->GetBlips().cbegin();
Core::Blips::const_iterator end = _Core->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();
}
// ================================================================================================
void Register_CBlip(HSQUIRRELVM vm)
{
RootTable(vm).Bind(_SC("SqBlip"),
Class< CBlip, NoConstructor< CBlip > >(vm, _SC("SqBlip"))
/* Metamethods */
// Metamethods
.Func(_SC("_cmp"), &CBlip::Cmp)
.SquirrelFunc(_SC("_typename"), &CBlip::Typename)
.Func(_SC("_tostring"), &CBlip::ToString)
/* Core Properties */
// Static values
.SetStaticValue(_SC("MaxID"), CBlip::Max)
// Core Properties
.Prop(_SC("ID"), &CBlip::GetID)
.Prop(_SC("Tag"), &CBlip::GetTag, &CBlip::SetTag)
.Prop(_SC("Data"), &CBlip::GetData, &CBlip::SetData)
.Prop(_SC("MaxID"), &CBlip::GetMaxID)
.Prop(_SC("Active"), &CBlip::IsActive)
/* Core Functions */
// Core Functions
.Func(_SC("Bind"), &CBlip::BindEvent)
/* Core Overloads */
// Core Overloads
.Overload< bool (CBlip::*)(void) >(_SC("Destroy"), &CBlip::Destroy)
.Overload< bool (CBlip::*)(Int32) >(_SC("Destroy"), &CBlip::Destroy)
.Overload< bool (CBlip::*)(Int32, Object &) >(_SC("Destroy"), &CBlip::Destroy)
/* Properties */
// Properties
.Prop(_SC("World"), &CBlip::GetWorld)
.Prop(_SC("Scale"), &CBlip::GetScale)
.Prop(_SC("Pos"), &CBlip::GetPosition)
@ -270,25 +346,24 @@ void Register_CBlip(HSQUIRRELVM vm)
.Prop(_SC("G"), &CBlip::GetColorG)
.Prop(_SC("B"), &CBlip::GetColorB)
.Prop(_SC("A"), &CBlip::GetColorA)
// Static Overloads
.StaticOverload< Object & (*)(Int32, Float32, Float32, Float32, Int32, Uint8, Uint8, Uint8, Uint8, Int32) >
(_SC("CreateEx"), &Blip_CreateEx)
.StaticOverload< Object & (*)(Int32, Float32, Float32, Float32, Int32, Uint8, Uint8, Uint8, Uint8, Int32, Int32, Object &) >
(_SC("CreateEx"), &Blip_CreateEx)
.StaticOverload< Object & (*)(Int32, Int32, Float32, Float32, Float32, Int32, Uint8, Uint8, Uint8, Uint8, Int32) >
(_SC("CreateEx"), &Blip_CreateEx)
.StaticOverload< Object & (*)(Int32, Int32, Float32, Float32, Float32, Int32, Uint8, Uint8, Uint8, Uint8, Int32, Int32, Object &) >
(_SC("CreateEx"), &Blip_CreateEx)
.StaticOverload< Object & (*)(Int32, const Vector3 &, Int32, const Color4 &, Int32) >
(_SC("Create"), &Blip_Create)
.StaticOverload< Object & (*)(Int32, const Vector3 &, Int32, const Color4 &, Int32, Int32, Object &) >
(_SC("Create"), &Blip_Create)
.StaticOverload< Object & (*)(Int32, Int32, const Vector3 &, Int32, const Color4 &, Int32) >
(_SC("Create"), &Blip_Create)
.StaticOverload< Object & (*)(Int32, Int32, const Vector3 &, Int32, const Color4 &, Int32, Int32, Object &) >
(_SC("Create"), &Blip_Create)
);
RootTable(vm)
.Overload< Object & (*)(Int32, Float32, Float32, Float32, Int32, Uint8, Uint8, Uint8, Uint8, Int32) >
(_SC("CreateBlipEx"), &CreateBlipEx)
.Overload< Object & (*)(Int32, Float32, Float32, Float32, Int32, Uint8, Uint8, Uint8, Uint8, Int32, Int32, Object &) >
(_SC("CreateBlipEx"), &CreateBlipEx)
.Overload< Object & (*)(Int32, Int32, Float32, Float32, Float32, Int32, Uint8, Uint8, Uint8, Uint8, Int32) >
(_SC("CreateBlipEx"), &CreateBlipEx)
.Overload< Object & (*)(Int32, Int32, Float32, Float32, Float32, Int32, Uint8, Uint8, Uint8, Uint8, Int32, Int32, Object &) >
(_SC("CreateBlipEx"), &CreateBlipEx)
.Overload< Object & (*)(Int32, const Vector3 &, Int32, const Color4 &, Int32) >
(_SC("CreateBlip"), &CreateBlip)
.Overload< Object & (*)(Int32, const Vector3 &, Int32, const Color4 &, Int32, Int32, Object &) >
(_SC("CreateBlip"), &CreateBlip)
.Overload< Object & (*)(Int32, Int32, const Vector3 &, Int32, const Color4 &, Int32) >
(_SC("CreateBlip"), &CreateBlip)
.Overload< Object & (*)(Int32, Int32, const Vector3 &, Int32, const Color4 &, Int32, Int32, Object &) >
(_SC("CreateBlip"), &CreateBlip);
}
} // Namespace:: SqMod
} // Namespace:: SqMod

View File

@ -8,7 +8,7 @@
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Manages Blip instances.
* Manages a single blip entity.
*/
class CBlip
{
@ -17,20 +17,19 @@ class CBlip
private:
/* --------------------------------------------------------------------------------------------
* Cached identifiers for fast integer to string conversion.
*/
static SQChar s_StrID[SQMOD_BLIP_POOL][8];
/* --------------------------------------------------------------------------------------------
* Identifier of the managed entity.
*/
Int32 m_ID;
/* --------------------------------------------------------------------------------------------
* User tag and data associated with this instance.
* User tag associated with this instance.
*/
String m_Tag;
/* --------------------------------------------------------------------------------------------
* User data associated with this instance.
*/
Object m_Data;
/* --------------------------------------------------------------------------------------------
@ -38,20 +37,22 @@ private:
*/
CBlip(Int32 id);
public:
/* --------------------------------------------------------------------------------------------
* Maximum possible number that could represent an identifier for this entity type.
*/
static const Int32 Max;
/* --------------------------------------------------------------------------------------------
* Copy constructor. (disabled)
*/
CBlip(const CBlip &);
CBlip(const CBlip &) = delete;
/* --------------------------------------------------------------------------------------------
* Copy assignment operator. (disabled)
* Move constructor. (disabled)
*/
CBlip & operator = (const CBlip &);
public:
// --------------------------------------------------------------------------------------------
static const Int32 Max;
CBlip(CBlip &&) = delete;
/* --------------------------------------------------------------------------------------------
* Destructor.
@ -59,14 +60,22 @@ public:
~CBlip();
/* --------------------------------------------------------------------------------------------
* See whether this instance manages a valid entity.
* Copy assignment operator. (disabled)
*/
bool Validate() const
CBlip & operator = (const CBlip &) = delete;
/* --------------------------------------------------------------------------------------------
* Move assignment operator. (disabled)
*/
CBlip & operator = (CBlip &&) = delete;
/* --------------------------------------------------------------------------------------------
* See whether this instance manages a valid entity otherwise throw an exception.
*/
void Validate() const
{
if (VALID_ENTITY(m_ID))
return true;
SqThrow("Invalid blip reference [%s]", m_Tag.c_str());
return false;
if (INVALID_ENTITY(m_ID))
SqThrowF("Invalid blip reference [%s]", m_Tag.c_str());
}
/* --------------------------------------------------------------------------------------------
@ -77,27 +86,33 @@ public:
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
CSStr ToString() const;
const String & ToString() const;
/* --------------------------------------------------------------------------------------------
* Used by the script engine to retrieve the name from instances of this type.
*/
static SQInteger Typename(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Retrieve the identifier of the entity managed by this instance.
*/
Int32 GetID() const { return m_ID; }
/* --------------------------------------------------------------------------------------------
* Retrieve the maximum possible identifier to an entity of this type.
*/
Int32 GetMaxID() const { return SQMOD_BLIP_POOL; }
Int32 GetID() const
{
return m_ID;
}
/* --------------------------------------------------------------------------------------------
* Check whether this instance manages a valid entity.
*/
bool IsActive() const { return VALID_ENTITY(m_ID); }
bool IsActive() const
{
return VALID_ENTITY(m_ID);
}
/* --------------------------------------------------------------------------------------------
* Retrieve the associated user tag.
*/
CSStr GetTag() const;
const String & GetTag() const;
/* --------------------------------------------------------------------------------------------
* Modify the associated user tag.
@ -115,29 +130,89 @@ public:
void SetData(Object & data);
/* --------------------------------------------------------------------------------------------
* Destroy the managed entity instance.
* Destroy the managed blip entity.
*/
bool Destroy()
{
return Destroy(0, NullObject());
}
/* --------------------------------------------------------------------------------------------
* Destroy the managed blip entity.
*/
bool Destroy(Int32 header)
{
return Destroy(header, NullObject());
}
/* --------------------------------------------------------------------------------------------
* Destroy the managed blip entity.
*/
bool Destroy(Int32 header, Object & payload);
bool Destroy() { return Destroy(0, NullObject()); }
bool Destroy(Int32 header) { return Destroy(header, NullObject()); }
// --------------------------------------------------------------------------------------------
bool BindEvent(Int32 evid, Object & env, Function & func) const;
/* --------------------------------------------------------------------------------------------
* Bind to an event supported by this entity type.
*/
void BindEvent(Int32 evid, Object & env, Function & func) const;
// --------------------------------------------------------------------------------------------
/* --------------------------------------------------------------------------------------------
* Retrieve the world in which the referenced blip entity exists.
*/
Int32 GetWorld() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the scale of the managed blip entity.
*/
Int32 GetScale() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the position of the managed blip entity.
*/
const Vector3 & GetPosition() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the color of the managed blip entity.
*/
const Color4 & GetColor() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the identifier of the sprite used by the managed blip entity.
*/
Int32 GetSprID() const;
// --------------------------------------------------------------------------------------------
/* --------------------------------------------------------------------------------------------
* Retrieve the position on the x axis of the managed blip entity.
*/
Float32 GetPosX() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the position on the y axis of the managed blip entity.
*/
Float32 GetPosY() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the position on the z axis of the managed blip entity.
*/
Float32 GetPosZ() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the red color of the managed blip entity.
*/
Int32 GetColorR() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the green color of the managed blip entity.
*/
Int32 GetColorG() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the blue color of the managed blip entity.
*/
Int32 GetColorB() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the alpha transparency of the managed blip entity.
*/
Int32 GetColorA() const;
};

View File

@ -19,15 +19,20 @@ Uint32 CCheckpoint::s_ColorB;
Uint32 CCheckpoint::s_ColorA;
// ------------------------------------------------------------------------------------------------
SQChar CCheckpoint::s_StrID[SQMOD_CHECKPOINT_POOL][8];
const Int32 CCheckpoint::Max = SQMOD_CHECKPOINT_POOL;
// ------------------------------------------------------------------------------------------------
const Int32 CCheckpoint::Max = SQMOD_CHECKPOINT_POOL;
SQInteger CCheckpoint::Typename(HSQUIRRELVM vm)
{
static SQChar name[] = _SC("SqCheckpoint");
sq_pushstring(vm, name, sizeof(name));
return 1;
}
// ------------------------------------------------------------------------------------------------
CCheckpoint::CCheckpoint(Int32 id)
: m_ID(VALID_ENTITYGETEX(id, SQMOD_CHECKPOINT_POOL))
, m_Tag(VALID_ENTITY(m_ID) ? s_StrID[m_ID] : _SC("-1"))
, m_Tag(ToStrF("%d", id))
{
/* ... */
}
@ -49,282 +54,373 @@ Int32 CCheckpoint::Cmp(const CCheckpoint & o) const
return -1;
}
CSStr CCheckpoint::ToString() const
// ------------------------------------------------------------------------------------------------
const String & CCheckpoint::ToString() const
{
return VALID_ENTITYEX(m_ID, SQMOD_CHECKPOINT_POOL) ? s_StrID[m_ID] : _SC("-1");
return m_Tag;
}
// ------------------------------------------------------------------------------------------------
CSStr CCheckpoint::GetTag() const
const String & CCheckpoint::GetTag() const
{
return m_Tag.c_str();
return m_Tag;
}
// ------------------------------------------------------------------------------------------------
void CCheckpoint::SetTag(CSStr tag)
{
m_Tag.assign(tag);
}
// ------------------------------------------------------------------------------------------------
Object & CCheckpoint::GetData()
{
if (Validate())
return m_Data;
return NullObject();
// Validate the managed identifier
Validate();
// Return the requested information
return m_Data;
}
// ------------------------------------------------------------------------------------------------
void CCheckpoint::SetData(Object & data)
{
if (Validate())
m_Data = data;
// Validate the managed identifier
Validate();
// Apply the specified value
m_Data = data;
}
// ------------------------------------------------------------------------------------------------
bool CCheckpoint::Destroy(Int32 header, Object & payload)
{
// Validate the managed identifier
Validate();
// Perform the requested operation
return _Core->DelCheckpoint(m_ID, header, payload);
}
// ------------------------------------------------------------------------------------------------
bool CCheckpoint::BindEvent(Int32 evid, Object & env, Function & func) const
void CCheckpoint::BindEvent(Int32 evid, Object & env, Function & func) const
{
if (!Validate())
return false;
// Validate the managed identifier
Validate();
// Obtain the function instance called for this event
Function & event = _Core->GetCheckpointEvent(m_ID, evid);
// Is the specified callback function null?
if (func.IsNull())
event.Release();
event.Release(); // Then release the current callback
// Assign the specified environment and function
else
event = Function(env.GetVM(), env, func.GetFunc());
return true;
}
// ------------------------------------------------------------------------------------------------
bool CCheckpoint::IsStreamedFor(CPlayer & player) const
{
// Is the specified player even valid?
if (!player.IsActive())
SqThrow("Invalid player argument: null");
else if (Validate())
return _Func->IsCheckpointStreamedForPlayer(m_ID, player.GetID());
return false;
SqThrowF("Invalid player argument: null");
// Validate the managed identifier
Validate();
// Return the requested information
return _Func->IsCheckpointStreamedForPlayer(m_ID, player.GetID());
}
// ------------------------------------------------------------------------------------------------
Int32 CCheckpoint::GetWorld() const
{
if (Validate())
return _Func->GetCheckpointWorld(m_ID);
return -1;
// Validate the managed identifier
Validate();
// Return the requested information
return _Func->GetCheckpointWorld(m_ID);
}
// ------------------------------------------------------------------------------------------------
void CCheckpoint::SetWorld(Int32 world) const
{
if (Validate())
_Func->SetCheckpointWorld(m_ID, world);
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->SetCheckpointWorld(m_ID, world);
}
// ------------------------------------------------------------------------------------------------
const Color4 & CCheckpoint::GetColor() const
{
// Validate the managed identifier
Validate();
// Clear previous color information, if any
s_Color4.Clear();
if (Validate())
{
_Func->GetCheckpointColor(m_ID, &s_ColorR, &s_ColorG, &s_ColorB, &s_ColorA);
s_Color4.Set(s_ColorR, s_ColorG, s_ColorB, s_ColorA);
}
// Query the server for the color values
_Func->GetCheckpointColor(m_ID, &s_ColorR, &s_ColorG, &s_ColorB, &s_ColorA);
// Convert and assign the retrieved values
s_Color4.Set(s_ColorR, s_ColorG, s_ColorB, s_ColorA);
// Return the requested information
return s_Color4;
}
// ------------------------------------------------------------------------------------------------
void CCheckpoint::SetColor(const Color4 & col) const
{
if (Validate())
_Func->SetCheckpointColor(m_ID, col.r, col.g, col.b, col.a);
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->SetCheckpointColor(m_ID, col.r, col.g, col.b, col.a);
}
// ------------------------------------------------------------------------------------------------
void CCheckpoint::SetColorEx(Uint8 r, Uint8 g, Uint8 b, Uint8 a) const
{
if (Validate())
_Func->SetCheckpointColor(m_ID, r, g, b, a);
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->SetCheckpointColor(m_ID, r, g, b, a);
}
// ------------------------------------------------------------------------------------------------
const Vector3 & CCheckpoint::GetPosition() const
{
// Validate the managed identifier
Validate();
// Clear previous position information, if any
s_Vector3.Clear();
if (Validate())
_Func->GetCheckpointPos(m_ID, &s_Vector3.x, &s_Vector3.y, &s_Vector3.z);
// Query the server for the position values
_Func->GetCheckpointPos(m_ID, &s_Vector3.x, &s_Vector3.y, &s_Vector3.z);
// Return the requested information
return s_Vector3;
}
// ------------------------------------------------------------------------------------------------
void CCheckpoint::SetPosition(const Vector3 & pos) const
{
if (Validate())
_Func->SetCheckpointPos(m_ID, pos.x, pos.y, pos.z);
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->SetCheckpointPos(m_ID, pos.x, pos.y, pos.z);
}
// ------------------------------------------------------------------------------------------------
void CCheckpoint::SetPositionEx(Float32 x, Float32 y, Float32 z) const
{
if (Validate())
_Func->SetCheckpointPos(m_ID, x, y, z);
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->SetCheckpointPos(m_ID, x, y, z);
}
// ------------------------------------------------------------------------------------------------
Float32 CCheckpoint::GetRadius() const
{
if (Validate())
_Func->GetCheckpointRadius(m_ID);
return 0;
// Validate the managed identifier
Validate();
// Return the requested information
return _Func->GetCheckpointRadius(m_ID);
}
// ------------------------------------------------------------------------------------------------
void CCheckpoint::SetRadius(Float32 radius) const
{
if (Validate())
_Func->SetCheckpointRadius(m_ID, radius);
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->SetCheckpointRadius(m_ID, radius);
}
// ------------------------------------------------------------------------------------------------
Object & CCheckpoint::GetOwner() const
{
if (Validate())
return _Core->GetPlayer(_Func->GetCheckpointOwner(m_ID)).mObj;
return NullObject();
// Validate the managed identifier
Validate();
// Return the requested information
return _Core->GetPlayer(_Func->GetCheckpointOwner(m_ID)).mObj;
}
// ------------------------------------------------------------------------------------------------
Int32 CCheckpoint::GetOwnerID() const
{
if (Validate())
return _Func->GetCheckpointOwner(m_ID);
return -1;
// Validate the managed identifier
Validate();
// Return the requested information
return _Func->GetCheckpointOwner(m_ID);
}
// ------------------------------------------------------------------------------------------------
Float32 CCheckpoint::GetPosX() const
{
// Validate the managed identifier
Validate();
// Clear previous position information, if any
s_Vector3.x = 0;
if (Validate())
_Func->GetCheckpointPos(m_ID, &s_Vector3.x, NULL, NULL);
// Query the server for the requested component value
_Func->GetCheckpointPos(m_ID, &s_Vector3.x, NULL, NULL);
// Return the requested information
return s_Vector3.x;
}
// ------------------------------------------------------------------------------------------------
Float32 CCheckpoint::GetPosY() const
{
// Validate the managed identifier
Validate();
// Clear previous position information, if any
s_Vector3.y = 0;
if (Validate())
_Func->GetCheckpointPos(m_ID, NULL, &s_Vector3.y, NULL);
// Query the server for the requested component value
_Func->GetCheckpointPos(m_ID, NULL, &s_Vector3.y, NULL);
// Return the requested information
return s_Vector3.y;
}
// ------------------------------------------------------------------------------------------------
Float32 CCheckpoint::GetPosZ() const
{
// Validate the managed identifier
Validate();
// Clear previous position information, if any
s_Vector3.z = 0;
if (Validate())
_Func->GetCheckpointPos(m_ID, NULL, NULL, &s_Vector3.z);
// Query the server for the requested component value
_Func->GetCheckpointPos(m_ID, NULL, NULL, &s_Vector3.z);
// Return the requested information
return s_Vector3.z;
}
// ------------------------------------------------------------------------------------------------
void CCheckpoint::SetPosX(Float32 x) const
{
if (Validate())
{
_Func->GetCheckpointPos(m_ID, NULL, &s_Vector3.y, &s_Vector3.z);
_Func->SetCheckpointPos(m_ID, x, s_Vector3.y, s_Vector3.z);
}
// Validate the managed identifier
Validate();
// Retrieve the current values for unchanged components
_Func->GetCheckpointPos(m_ID, NULL, &s_Vector3.y, &s_Vector3.z);
// Perform the requested operation
_Func->SetCheckpointPos(m_ID, x, s_Vector3.y, s_Vector3.z);
}
// ------------------------------------------------------------------------------------------------
void CCheckpoint::SetPosY(Float32 y) const
{
if (Validate())
{
_Func->GetCheckpointPos(m_ID, &s_Vector3.x, NULL, &s_Vector3.z);
_Func->SetCheckpointPos(m_ID, s_Vector3.x, y, s_Vector3.z);
}
// Validate the managed identifier
Validate();
// Retrieve the current values for unchanged components
_Func->GetCheckpointPos(m_ID, &s_Vector3.x, NULL, &s_Vector3.z);
// Perform the requested operation
_Func->SetCheckpointPos(m_ID, s_Vector3.x, y, s_Vector3.z);
}
// ------------------------------------------------------------------------------------------------
void CCheckpoint::SetPosZ(Float32 z) const
{
if (Validate())
{
_Func->GetCheckpointPos(m_ID, &s_Vector3.x, &s_Vector3.y, NULL);
_Func->SetCheckpointPos(m_ID, s_Vector3.z, s_Vector3.y, z);
}
// Validate the managed identifier
Validate();
// Retrieve the current values for unchanged components
_Func->GetCheckpointPos(m_ID, &s_Vector3.x, &s_Vector3.y, NULL);
// Perform the requested operation
_Func->SetCheckpointPos(m_ID, s_Vector3.z, s_Vector3.y, z);
}
// ------------------------------------------------------------------------------------------------
Uint32 CCheckpoint::GetColR() const
{
// Validate the managed identifier
Validate();
// Clear previous color information, if any
s_ColorR = 0;
if (Validate())
_Func->GetCheckpointColor(m_ID, &s_ColorR, NULL, NULL, NULL);
// Query the server for the requested component value
_Func->GetCheckpointColor(m_ID, &s_ColorR, NULL, NULL, NULL);
// Return the requested information
return s_ColorR;
}
// ------------------------------------------------------------------------------------------------
Uint32 CCheckpoint::GetColG() const
{
// Validate the managed identifier
Validate();
// Clear previous color information, if any
s_ColorG = 0;
if (Validate())
_Func->GetCheckpointColor(m_ID, NULL, &s_ColorG, NULL, NULL);
// Query the server for the requested component value
_Func->GetCheckpointColor(m_ID, NULL, &s_ColorG, NULL, NULL);
// Return the requested information
return s_ColorG;
}
// ------------------------------------------------------------------------------------------------
Uint32 CCheckpoint::GetColB() const
{
// Validate the managed identifier
Validate();
// Clear previous color information, if any
s_ColorB = 0;
if (Validate())
_Func->GetCheckpointColor(m_ID, NULL, NULL, &s_ColorB, NULL);
// Query the server for the requested component value
_Func->GetCheckpointColor(m_ID, NULL, NULL, &s_ColorB, NULL);
// Return the requested information
return s_ColorB;
}
// ------------------------------------------------------------------------------------------------
Uint32 CCheckpoint::GetColA() const
{
// Validate the managed identifier
Validate();
// Clear previous color information, if any
s_ColorA = 0;
if (Validate())
_Func->GetCheckpointColor(m_ID, NULL, NULL, NULL, &s_ColorA);
// Query the server for the requested component value
_Func->GetCheckpointColor(m_ID, NULL, NULL, NULL, &s_ColorA);
// Return the requested information
return s_ColorA;
}
// ------------------------------------------------------------------------------------------------
void CCheckpoint::SetColR(Uint32 r) const
{
if (Validate())
{
_Func->GetCheckpointColor(m_ID, NULL, &s_ColorG, &s_ColorB, &s_ColorA);
_Func->SetCheckpointColor(m_ID, r, s_ColorG, s_ColorB, s_ColorA);
}
}
void CCheckpoint::SetColG(Uint32 g) const
{
if (Validate())
{
_Func->GetCheckpointColor(m_ID, &s_ColorR, NULL, &s_ColorB, &s_ColorA);
_Func->SetCheckpointColor(m_ID, s_ColorR, g, s_ColorB, s_ColorA);
}
}
void CCheckpoint::SetColB(Uint32 b) const
{
if (Validate())
{
_Func->GetCheckpointColor(m_ID, &s_ColorB, &s_ColorG, NULL, &s_ColorA);
_Func->SetCheckpointColor(m_ID, s_ColorB, s_ColorG, b, s_ColorA);
}
}
void CCheckpoint::SetColA(Uint32 a) const
{
if (Validate())
{
_Func->GetCheckpointColor(m_ID, &s_ColorA, &s_ColorG, &s_ColorB, NULL);
_Func->SetCheckpointColor(m_ID, s_ColorA, s_ColorG, s_ColorB, a);
}
// Validate the managed identifier
Validate();
// Retrieve the current values for unchanged components
_Func->GetCheckpointColor(m_ID, NULL, &s_ColorG, &s_ColorB, &s_ColorA);
// Perform the requested operation
_Func->SetCheckpointColor(m_ID, r, s_ColorG, s_ColorB, s_ColorA);
}
// ------------------------------------------------------------------------------------------------
static Object & CreateCheckpointEx(CPlayer & player, Int32 world, Float32 x, Float32 y, Float32 z,
void CCheckpoint::SetColG(Uint32 g) const
{
// Validate the managed identifier
Validate();
// Retrieve the current values for unchanged components
_Func->GetCheckpointColor(m_ID, &s_ColorR, NULL, &s_ColorB, &s_ColorA);
// Perform the requested operation
_Func->SetCheckpointColor(m_ID, s_ColorR, g, s_ColorB, s_ColorA);
}
// ------------------------------------------------------------------------------------------------
void CCheckpoint::SetColB(Uint32 b) const
{
// Validate the managed identifier
Validate();
// Retrieve the current values for unchanged components
_Func->GetCheckpointColor(m_ID, &s_ColorB, &s_ColorG, NULL, &s_ColorA);
// Perform the requested operation
_Func->SetCheckpointColor(m_ID, s_ColorB, s_ColorG, b, s_ColorA);
}
// ------------------------------------------------------------------------------------------------
void CCheckpoint::SetColA(Uint32 a) const
{
// Validate the managed identifier
Validate();
// Retrieve the current values for unchanged components
_Func->GetCheckpointColor(m_ID, &s_ColorA, &s_ColorG, &s_ColorB, NULL);
// Perform the requested operation
_Func->SetCheckpointColor(m_ID, s_ColorA, s_ColorG, s_ColorB, a);
}
// ------------------------------------------------------------------------------------------------
static Object & Checkpoint_CreateEx(CPlayer & player, Int32 world, Float32 x, Float32 y, Float32 z,
Uint8 r, Uint8 g, Uint8 b, Uint8 a, Float32 radius)
{
return _Core->NewCheckpoint(player.GetID(), world, x, y, z, r, g, b, a, radius,
SQMOD_CREATE_DEFAULT, NullObject());
}
static Object & CreateCheckpointEx(CPlayer & player, Int32 world, Float32 x, Float32 y, Float32 z,
static Object & Checkpoint_CreateEx(CPlayer & player, Int32 world, Float32 x, Float32 y, Float32 z,
Uint8 r, Uint8 g, Uint8 b, Uint8 a, Float32 radius,
Int32 header, Object & payload)
{
@ -332,7 +428,7 @@ static Object & CreateCheckpointEx(CPlayer & player, Int32 world, Float32 x, Flo
}
// ------------------------------------------------------------------------------------------------
static Object & CreateCheckpoint(CPlayer & player, Int32 world, const Vector3 & pos,
static Object & Checkpoint_Create(CPlayer & player, Int32 world, const Vector3 & pos,
const Color4 & color, Float32 radius)
{
return _Core->NewCheckpoint(player.GetID(), world, pos.x, pos.y, pos.z,
@ -340,7 +436,7 @@ static Object & CreateCheckpoint(CPlayer & player, Int32 world, const Vector3 &
SQMOD_CREATE_DEFAULT, NullObject());
}
static Object & CreateCheckpoint(CPlayer & player, Int32 world, const Vector3 & pos,
static Object & Checkpoint_Create(CPlayer & player, Int32 world, const Vector3 & pos,
const Color4 & color, Float32 radius, Int32 header, Object & payload)
{
return _Core->NewCheckpoint(player.GetID(), world, pos.x, pos.y, pos.z,
@ -352,22 +448,24 @@ void Register_CCheckpoint(HSQUIRRELVM vm)
{
RootTable(vm).Bind(_SC("SqCheckpoint"),
Class< CCheckpoint, NoConstructor< CCheckpoint > >(vm, _SC("SqCheckpoint"))
/* Metamethods */
// Metamethods
.Func(_SC("_cmp"), &CCheckpoint::Cmp)
.SquirrelFunc(_SC("_typename"), &CCheckpoint::Typename)
.Func(_SC("_tostring"), &CCheckpoint::ToString)
/* Core Properties */
// Static values
.SetStaticValue(_SC("MaxID"), CCheckpoint::Max)
// Core Properties
.Prop(_SC("ID"), &CCheckpoint::GetID)
.Prop(_SC("Tag"), &CCheckpoint::GetTag, &CCheckpoint::SetTag)
.Prop(_SC("Data"), &CCheckpoint::GetData, &CCheckpoint::SetData)
.Prop(_SC("MaxID"), &CCheckpoint::GetMaxID)
.Prop(_SC("Active"), &CCheckpoint::IsActive)
/* Core Functions */
// Core Functions
.Func(_SC("Bind"), &CCheckpoint::BindEvent)
/* Core Overloads */
// Core Overloads
.Overload< bool (CCheckpoint::*)(void) >(_SC("Destroy"), &CCheckpoint::Destroy)
.Overload< bool (CCheckpoint::*)(Int32) >(_SC("Destroy"), &CCheckpoint::Destroy)
.Overload< bool (CCheckpoint::*)(Int32, Object &) >(_SC("Destroy"), &CCheckpoint::Destroy)
/* Properties */
// Properties
.Prop(_SC("World"), &CCheckpoint::GetWorld, &CCheckpoint::SetWorld)
.Prop(_SC("Color"), &CCheckpoint::GetColor, &CCheckpoint::SetColor)
.Prop(_SC("Pos"), &CCheckpoint::GetPosition, &CCheckpoint::SetPosition)
@ -382,22 +480,21 @@ void Register_CCheckpoint(HSQUIRRELVM vm)
.Prop(_SC("G"), &CCheckpoint::GetColG, &CCheckpoint::SetColG)
.Prop(_SC("B"), &CCheckpoint::GetColB, &CCheckpoint::SetColB)
.Prop(_SC("A"), &CCheckpoint::GetColA, &CCheckpoint::SetColA)
/* Functions */
// Functions
.Func(_SC("StreamedFor"), &CCheckpoint::IsStreamedFor)
.Func(_SC("SetColor"), &CCheckpoint::SetColorEx)
.Func(_SC("SetPos"), &CCheckpoint::SetPositionEx)
.Func(_SC("SetPosition"), &CCheckpoint::SetPositionEx)
// Static Overloads
.StaticOverload< Object & (*)(CPlayer &, Int32, Float32, Float32, Float32, Uint8, Uint8, Uint8, Uint8, Float32) >
(_SC("CreateEx"), &Checkpoint_CreateEx)
.StaticOverload< Object & (*)(CPlayer &, Int32, Float32, Float32, Float32, Uint8, Uint8, Uint8, Uint8, Float32, Int32, Object &) >
(_SC("CreateEx"), &Checkpoint_CreateEx)
.StaticOverload< Object & (*)(CPlayer &, Int32, const Vector3 &, const Color4 &, Float32) >
(_SC("Create"), &Checkpoint_Create)
.StaticOverload< Object & (*)(CPlayer &, Int32, const Vector3 &, const Color4 &, Float32, Int32, Object &) >
(_SC("Create"), &Checkpoint_Create)
);
RootTable(vm)
.Overload< Object & (*)(CPlayer &, Int32, Float32, Float32, Float32, Uint8, Uint8, Uint8, Uint8, Float32) >
(_SC("CreateCheckpointEx"), &CreateCheckpointEx)
.Overload< Object & (*)(CPlayer &, Int32, Float32, Float32, Float32, Uint8, Uint8, Uint8, Uint8, Float32, Int32, Object &) >
(_SC("CreateCheckpointEx"), &CreateCheckpointEx)
.Overload< Object & (*)(CPlayer &, Int32, const Vector3 &, const Color4 &, Float32) >
(_SC("CreateCheckpoint"), &CreateCheckpoint)
.Overload< Object & (*)(CPlayer &, Int32, const Vector3 &, const Color4 &, Float32, Int32, Object &) >
(_SC("CreateCheckpoint"), &CreateCheckpoint);
}
} // Namespace:: SqMod
} // Namespace:: SqMod

View File

@ -8,7 +8,7 @@
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Manages Checkpoint instances.
* Manages a single checkpoint entity.
*/
class CCheckpoint
{
@ -24,20 +24,19 @@ private:
// --------------------------------------------------------------------------------------------
static Uint32 s_ColorR, s_ColorG, s_ColorB, s_ColorA;
/* --------------------------------------------------------------------------------------------
* Cached identifiers for fast integer to string conversion.
*/
static SQChar s_StrID[SQMOD_CHECKPOINT_POOL][8];
/* --------------------------------------------------------------------------------------------
* Identifier of the managed entity.
*/
Int32 m_ID;
/* --------------------------------------------------------------------------------------------
* User tag and data associated with this instance.
* User tag associated with this instance.
*/
String m_Tag;
/* --------------------------------------------------------------------------------------------
* User data associated with this instance.
*/
Object m_Data;
/* --------------------------------------------------------------------------------------------
@ -45,20 +44,22 @@ private:
*/
CCheckpoint(Int32 id);
public:
/* --------------------------------------------------------------------------------------------
* Maximum possible number that could represent an identifier for this entity type.
*/
static const Int32 Max;
/* --------------------------------------------------------------------------------------------
* Copy constructor. (disabled)
*/
CCheckpoint(const CCheckpoint &);
CCheckpoint(const CCheckpoint &) = delete;
/* --------------------------------------------------------------------------------------------
* Copy assignment operator. (disabled)
* Move constructor. (disabled)
*/
CCheckpoint & operator = (const CCheckpoint &);
public:
// --------------------------------------------------------------------------------------------
static const Int32 Max;
CCheckpoint(CCheckpoint &&) = delete;
/* --------------------------------------------------------------------------------------------
* Destructor.
@ -66,14 +67,22 @@ public:
~CCheckpoint();
/* --------------------------------------------------------------------------------------------
* See whether this instance manages a valid entity.
* Copy assignment operator. (disabled)
*/
bool Validate() const
CCheckpoint & operator = (const CCheckpoint &) = delete;
/* --------------------------------------------------------------------------------------------
* Move assignment operator. (disabled)
*/
CCheckpoint & operator = (CCheckpoint &&) = delete;
/* --------------------------------------------------------------------------------------------
* See whether this instance manages a valid entity otherwise throw an exception.
*/
void Validate() const
{
if (VALID_ENTITY(m_ID))
return true;
SqThrow("Invalid checkpoint reference [%s]", m_Tag.c_str());
return false;
if (INVALID_ENTITY(m_ID))
SqThrowF("Invalid checkpoint reference [%s]", m_Tag.c_str());
}
/* --------------------------------------------------------------------------------------------
@ -84,27 +93,33 @@ public:
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
CSStr ToString() const;
const String & ToString() const;
/* --------------------------------------------------------------------------------------------
* Used by the script engine to retrieve the name from instances of this type.
*/
static SQInteger Typename(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Retrieve the identifier of the entity managed by this instance.
*/
Int32 GetID() const { return m_ID; }
/* --------------------------------------------------------------------------------------------
* Retrieve the maximum possible identifier to an entity of this type.
*/
Int32 GetMaxID() const { return SQMOD_CHECKPOINT_POOL; }
Int32 GetID() const
{
return m_ID;
}
/* --------------------------------------------------------------------------------------------
* Check whether this instance manages a valid entity.
*/
bool IsActive() const { return VALID_ENTITY(m_ID); }
bool IsActive() const
{
return VALID_ENTITY(m_ID);
}
/* --------------------------------------------------------------------------------------------
* Retrieve the associated user tag.
*/
CSStr GetTag() const;
const String & GetTag() const;
/* --------------------------------------------------------------------------------------------
* Modify the associated user tag.
@ -120,45 +135,166 @@ public:
* Modify the associated user data.
*/
void SetData(Object & data);
// --------------------------------------------------------------------------------------------
/* --------------------------------------------------------------------------------------------
* Destroy the managed checkpoint entity.
*/
bool Destroy()
{
return Destroy(0, NullObject());
}
/* --------------------------------------------------------------------------------------------
* Destroy the managed checkpoint entity.
*/
bool Destroy(Int32 header)
{
return Destroy(header, NullObject());
}
/* --------------------------------------------------------------------------------------------
* Destroy the managed checkpoint entity.
*/
bool Destroy(Int32 header, Object & payload);
bool Destroy() { return Destroy(0, NullObject()); }
bool Destroy(Int32 header) { return Destroy(header, NullObject()); }
// --------------------------------------------------------------------------------------------
bool BindEvent(Int32 evid, Object & env, Function & func) const;
/* --------------------------------------------------------------------------------------------
* Bind to an event supported by this entity type.
*/
void BindEvent(Int32 evid, Object & env, Function & func) const;
// --------------------------------------------------------------------------------------------
/* --------------------------------------------------------------------------------------------
* See if the managed checkpoint entity is streamed for the specified player.
*/
bool IsStreamedFor(CPlayer & player) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the world in which the managed checkpoint entity exists.
*/
Int32 GetWorld() const;
/* --------------------------------------------------------------------------------------------
* Modify the world in which the managed checkpoint entity exists.
*/
void SetWorld(Int32 world) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the color of the managed checkpoint entity.
*/
const Color4 & GetColor() const;
/* --------------------------------------------------------------------------------------------
* Modify the color of the managed checkpoint entity.
*/
void SetColor(const Color4 & col) const;
/* --------------------------------------------------------------------------------------------
* Modify the color of the managed checkpoint entity.
*/
void SetColorEx(Uint8 r, Uint8 g, Uint8 b, Uint8 a) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the position of the managed checkpoint entity.
*/
const Vector3 & GetPosition() const;
/* --------------------------------------------------------------------------------------------
* Modify the position of the managed checkpoint entity.
*/
void SetPosition(const Vector3 & pos) const;
/* --------------------------------------------------------------------------------------------
* Modify the position of the managed checkpoint entity.
*/
void SetPositionEx(Float32 x, Float32 y, Float32 z) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the radius of the managed checkpoint entity.
*/
Float32 GetRadius() const;
/* --------------------------------------------------------------------------------------------
* Modify the radius of the managed checkpoint entity.
*/
void SetRadius(Float32 radius) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the owner of the managed checkpoint entity.
*/
Object & GetOwner() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the owner identifier of the managed checkpoint entity.
*/
Int32 GetOwnerID() const;
// --------------------------------------------------------------------------------------------
/* --------------------------------------------------------------------------------------------
* Retrieve the position on the x axis of the managed checkpoint entity.
*/
Float32 GetPosX() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the position on the y axis of the managed checkpoint entity.
*/
Float32 GetPosY() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the position on the z axis of the managed checkpoint entity.
*/
Float32 GetPosZ() const;
/* --------------------------------------------------------------------------------------------
* Modify the position on the x axis of the managed checkpoint entity.
*/
void SetPosX(Float32 x) const;
/* --------------------------------------------------------------------------------------------
* Modify the position on the y axis of the managed checkpoint entity.
*/
void SetPosY(Float32 y) const;
/* --------------------------------------------------------------------------------------------
* Modify the position on the z axis of the managed checkpoint entity.
*/
void SetPosZ(Float32 z) const;
// --------------------------------------------------------------------------------------------
/* --------------------------------------------------------------------------------------------
* Retrieve the red color of the managed checkpoint entity.
*/
Uint32 GetColR() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the green color of the managed checkpoint entity.
*/
Uint32 GetColG() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the blue color of the managed checkpoint entity.
*/
Uint32 GetColB() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the alpha transparency of the managed checkpoint entity.
*/
Uint32 GetColA() const;
/* --------------------------------------------------------------------------------------------
* Modify the red color of the managed checkpoint entity.
*/
void SetColR(Uint32 r) const;
/* --------------------------------------------------------------------------------------------
* Modify the green color of the managed checkpoint entity.
*/
void SetColG(Uint32 g) const;
/* --------------------------------------------------------------------------------------------
* Modify the blue color of the managed checkpoint entity.
*/
void SetColB(Uint32 b) const;
/* --------------------------------------------------------------------------------------------
* Modify the alpha transparency of the managed checkpoint entity.
*/
void SetColA(Uint32 a) const;
};

View File

@ -18,15 +18,20 @@ Uint32 CForcefield::s_ColorG;
Uint32 CForcefield::s_ColorB;
// ------------------------------------------------------------------------------------------------
SQChar CForcefield::s_StrID[SQMOD_FORCEFIELD_POOL][8];
const Int32 CForcefield::Max = SQMOD_FORCEFIELD_POOL;
// ------------------------------------------------------------------------------------------------
const Int32 CForcefield::Max = SQMOD_FORCEFIELD_POOL;
SQInteger CForcefield::Typename(HSQUIRRELVM vm)
{
static SQChar name[] = _SC("SqForcefield");
sq_pushstring(vm, name, sizeof(name));
return 1;
}
// ------------------------------------------------------------------------------------------------
CForcefield::CForcefield(Int32 id)
: m_ID(VALID_ENTITYGETEX(id, SQMOD_FORCEFIELD_POOL))
, m_Tag(VALID_ENTITY(m_ID) ? s_StrID[m_ID] : _SC("-1"))
, m_Tag(ToStrF("%d", id))
{
/* ... */
}
@ -48,265 +53,349 @@ Int32 CForcefield::Cmp(const CForcefield & o) const
return -1;
}
CSStr CForcefield::ToString() const
// ------------------------------------------------------------------------------------------------
const String & CForcefield::ToString() const
{
return VALID_ENTITYEX(m_ID, SQMOD_FORCEFIELD_POOL) ? s_StrID[m_ID] : _SC("-1");
return m_Tag;
}
// ------------------------------------------------------------------------------------------------
CSStr CForcefield::GetTag() const
const String & CForcefield::GetTag() const
{
return m_Tag.c_str();
return m_Tag;
}
// ------------------------------------------------------------------------------------------------
void CForcefield::SetTag(CSStr tag)
{
m_Tag.assign(tag);
}
// ------------------------------------------------------------------------------------------------
Object & CForcefield::GetData()
{
if (Validate())
return m_Data;
return NullObject();
// Validate the managed identifier
Validate();
// Return the requested information
return m_Data;
}
// ------------------------------------------------------------------------------------------------
void CForcefield::SetData(Object & data)
{
if (Validate())
m_Data = data;
// Validate the managed identifier
Validate();
// Apply the specified value
m_Data = data;
}
// ------------------------------------------------------------------------------------------------
bool CForcefield::Destroy(Int32 header, Object & payload)
{
// Validate the managed identifier
Validate();
// Perform the requested operation
return _Core->DelForcefield(m_ID, header, payload);
}
// ------------------------------------------------------------------------------------------------
bool CForcefield::BindEvent(Int32 evid, Object & env, Function & func) const
void CForcefield::BindEvent(Int32 evid, Object & env, Function & func) const
{
if (!Validate())
return false;
// Validate the managed identifier
Validate();
// Obtain the function instance called for this event
Function & event = _Core->GetForcefieldEvent(m_ID, evid);
// Is the specified callback function null?
if (func.IsNull())
event.Release();
event.Release(); // Then release the current callback
// Assign the specified environment and function
else
event = Function(env.GetVM(), env, func.GetFunc());
return true;
}
// ------------------------------------------------------------------------------------------------
bool CForcefield::IsStreamedFor(CPlayer & player) const
{
// Is the specified player even valid?
if (!player.IsActive())
SqThrow("Invalid player argument: null");
else if (Validate())
return _Func->IsSphereStreamedForPlayer(m_ID, player.GetID());
return false;
SqThrowF("Invalid player argument: null");
// Validate the managed identifier
Validate();
// Return the requested information
return _Func->IsSphereStreamedForPlayer(m_ID, player.GetID());
}
// ------------------------------------------------------------------------------------------------
Int32 CForcefield::GetWorld() const
{
if (Validate())
return _Func->GetSphereWorld(m_ID);
return -1;
// Validate the managed identifier
Validate();
// Return the requested information
return _Func->GetSphereWorld(m_ID);
}
// ------------------------------------------------------------------------------------------------
void CForcefield::SetWorld(Int32 world) const
{
if (Validate())
_Func->SetSphereWorld(m_ID, world);
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->SetSphereWorld(m_ID, world);
}
// ------------------------------------------------------------------------------------------------
const Color3 & CForcefield::GetColor() const
{
// Validate the managed identifier
Validate();
// Clear previous color information, if any
s_Color3.Clear();
if (Validate())
{
_Func->GetSphereColor(m_ID, &s_ColorR, &s_ColorG, &s_ColorB);
s_Color3.Set(s_ColorR, s_ColorG, s_ColorB);
}
// Query the server for the color values
_Func->GetSphereColor(m_ID, &s_ColorR, &s_ColorG, &s_ColorB);
// Convert and assign the retrieved values
s_Color3.Set(s_ColorR, s_ColorG, s_ColorB);
// Return the requested information
return s_Color3;
}
// ------------------------------------------------------------------------------------------------
void CForcefield::SetColor(const Color3 & col) const
{
if (Validate())
_Func->SetSphereColor(m_ID, col.r, col.g, col.b);
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->SetSphereColor(m_ID, col.r, col.g, col.b);
}
// ------------------------------------------------------------------------------------------------
void CForcefield::SetColorEx(Uint8 r, Uint8 g, Uint8 b) const
{
if (Validate())
_Func->SetSphereColor(m_ID, r, g, b);
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->SetSphereColor(m_ID, r, g, b);
}
// ------------------------------------------------------------------------------------------------
const Vector3 & CForcefield::GetPosition() const
{
// Validate the managed identifier
Validate();
// Clear previous position information, if any
s_Vector3.Clear();
if (Validate())
_Func->GetSpherePos(m_ID, &s_Vector3.x, &s_Vector3.y, &s_Vector3.z);
// Query the server for the position values
_Func->GetSpherePos(m_ID, &s_Vector3.x, &s_Vector3.y, &s_Vector3.z);
// Return the requested information
return s_Vector3;
}
// ------------------------------------------------------------------------------------------------
void CForcefield::SetPosition(const Vector3 & pos) const
{
if (Validate())
_Func->SetSpherePos(m_ID, pos.x, pos.y, pos.z);
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->SetSpherePos(m_ID, pos.x, pos.y, pos.z);
}
// ------------------------------------------------------------------------------------------------
void CForcefield::SetPositionEx(Float32 x, Float32 y, Float32 z) const
{
if (Validate())
_Func->SetSpherePos(m_ID, x, y, z);
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->SetSpherePos(m_ID, x, y, z);
}
// ------------------------------------------------------------------------------------------------
Float32 CForcefield::GetRadius() const
{
if (Validate())
_Func->GetSphereRadius(m_ID);
return 0;
// Validate the managed identifier
Validate();
// Return the requested information
return _Func->GetSphereRadius(m_ID);
}
// ------------------------------------------------------------------------------------------------
void CForcefield::SetRadius(Float32 radius) const
{
if (Validate())
_Func->SetSphereRadius(m_ID, radius);
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->SetSphereRadius(m_ID, radius);
}
// ------------------------------------------------------------------------------------------------
Object & CForcefield::GetOwner() const
{
if (Validate())
return _Core->GetPlayer(_Func->GetSphereOwner(m_ID)).mObj;
return NullObject();
// Validate the managed identifier
Validate();
// Return the requested information
return _Core->GetPlayer(_Func->GetSphereOwner(m_ID)).mObj;
}
// ------------------------------------------------------------------------------------------------
Int32 CForcefield::GetOwnerID() const
{
if (Validate())
_Func->GetSphereOwner(m_ID);
return -1;
// Validate the managed identifier
Validate();
// Return the requested information
return _Func->GetSphereOwner(m_ID);
}
// ------------------------------------------------------------------------------------------------
Float32 CForcefield::GetPosX() const
{
// Validate the managed identifier
Validate();
// Clear previous position information, if any
s_Vector3.x = 0;
if (Validate())
_Func->GetSpherePos(m_ID, &s_Vector3.x, NULL, NULL);
// Query the server for the requested component value
_Func->GetSpherePos(m_ID, &s_Vector3.x, NULL, NULL);
// Return the requested information
return s_Vector3.x;
}
// ------------------------------------------------------------------------------------------------
Float32 CForcefield::GetPosY() const
{
// Validate the managed identifier
Validate();
// Clear previous position information, if any
s_Vector3.y = 0;
if (Validate())
_Func->GetSpherePos(m_ID, NULL, &s_Vector3.y, NULL);
// Query the server for the requested component value
_Func->GetSpherePos(m_ID, NULL, &s_Vector3.y, NULL);
// Return the requested information
return s_Vector3.y;
}
// ------------------------------------------------------------------------------------------------
Float32 CForcefield::GetPosZ() const
{
// Validate the managed identifier
Validate();
// Clear previous position information, if any
s_Vector3.z = 0;
if (Validate())
_Func->GetSpherePos(m_ID, NULL, NULL, &s_Vector3.z);
// Query the server for the requested component value
_Func->GetSpherePos(m_ID, NULL, NULL, &s_Vector3.z);
// Return the requested information
return s_Vector3.z;
}
// ------------------------------------------------------------------------------------------------
void CForcefield::SetPosX(Float32 x) const
{
if (Validate())
{
_Func->GetSpherePos(m_ID, NULL, &s_Vector3.y, &s_Vector3.z);
_Func->SetSpherePos(m_ID, x, s_Vector3.y, s_Vector3.z);
}
// Validate the managed identifier
Validate();
// Retrieve the current values for unchanged components
_Func->GetSpherePos(m_ID, NULL, &s_Vector3.y, &s_Vector3.z);
// Perform the requested operation
_Func->SetSpherePos(m_ID, x, s_Vector3.y, s_Vector3.z);
}
// ------------------------------------------------------------------------------------------------
void CForcefield::SetPosY(Float32 y) const
{
if (Validate())
{
_Func->GetSpherePos(m_ID, &s_Vector3.x, NULL, &s_Vector3.z);
_Func->SetSpherePos(m_ID, s_Vector3.x, y, s_Vector3.z);
}
// Validate the managed identifier
Validate();
// Retrieve the current values for unchanged components
_Func->GetSpherePos(m_ID, &s_Vector3.x, NULL, &s_Vector3.z);
// Perform the requested operation
_Func->SetSpherePos(m_ID, s_Vector3.x, y, s_Vector3.z);
}
// ------------------------------------------------------------------------------------------------
void CForcefield::SetPosZ(Float32 z) const
{
if (Validate())
{
_Func->GetSpherePos(m_ID, &s_Vector3.x, &s_Vector3.y, NULL);
_Func->SetSpherePos(m_ID, s_Vector3.z, s_Vector3.y, z);
}
// Validate the managed identifier
Validate();
// Retrieve the current values for unchanged components
_Func->GetSpherePos(m_ID, &s_Vector3.x, &s_Vector3.y, NULL);
// Perform the requested operation
_Func->SetSpherePos(m_ID, s_Vector3.z, s_Vector3.y, z);
}
// ------------------------------------------------------------------------------------------------
Uint32 CForcefield::GetColR() const
{
// Validate the managed identifier
Validate();
// Clear previous color information, if any
s_ColorR = 0;
if (Validate())
_Func->GetSphereColor(m_ID, &s_ColorR, NULL, NULL);
// Query the server for the requested component value
_Func->GetSphereColor(m_ID, &s_ColorR, NULL, NULL);
// Return the requested information
return s_ColorR;
}
// ------------------------------------------------------------------------------------------------
Uint32 CForcefield::GetColG() const
{
// Validate the managed identifier
Validate();
// Query the server for the requested component value
s_ColorG = 0;
if (Validate())
_Func->GetSphereColor(m_ID, NULL, &s_ColorG, NULL);
// Query the server for the requested component value
_Func->GetSphereColor(m_ID, NULL, &s_ColorG, NULL);
// Return the requested information
return s_ColorG;
}
// ------------------------------------------------------------------------------------------------
Uint32 CForcefield::GetColB() const
{
// Validate the managed identifier
Validate();
// Query the server for the requested component value
s_ColorB = 0;
if (Validate())
_Func->GetSphereColor(m_ID, NULL, NULL, &s_ColorB);
// Query the server for the requested component value
_Func->GetSphereColor(m_ID, NULL, NULL, &s_ColorB);
// Return the requested information
return s_ColorB;
}
// ------------------------------------------------------------------------------------------------
void CForcefield::SetColR(Uint32 r) const
{
if (Validate())
{
_Func->GetSphereColor(m_ID, NULL, &s_ColorG, &s_ColorB);
_Func->SetSphereColor(m_ID, r, s_ColorG, s_ColorB);
}
}
void CForcefield::SetColG(Uint32 g) const
{
if (Validate())
{
_Func->GetSphereColor(m_ID, &s_ColorR, NULL, &s_ColorB);
_Func->SetSphereColor(m_ID, s_ColorR, g, s_ColorB);
}
}
void CForcefield::SetColB(Uint32 b) const
{
if (Validate())
{
_Func->GetSphereColor(m_ID, &s_ColorB, &s_ColorG, NULL);
_Func->SetSphereColor(m_ID, s_ColorB, s_ColorG, b);
}
// Validate the managed identifier
Validate();
// Retrieve the current values for unchanged components
_Func->GetSphereColor(m_ID, NULL, &s_ColorG, &s_ColorB);
// Perform the requested operation
_Func->SetSphereColor(m_ID, r, s_ColorG, s_ColorB);
}
// ------------------------------------------------------------------------------------------------
static Object & CreateForcefieldEx(CPlayer & player, Int32 world, Float32 x, Float32 y, Float32 z,
void CForcefield::SetColG(Uint32 g) const
{
// Validate the managed identifier
Validate();
// Retrieve the current values for unchanged components
_Func->GetSphereColor(m_ID, &s_ColorR, NULL, &s_ColorB);
// Perform the requested operation
_Func->SetSphereColor(m_ID, s_ColorR, g, s_ColorB);
}
// ------------------------------------------------------------------------------------------------
void CForcefield::SetColB(Uint32 b) const
{
// Validate the managed identifier
Validate();
// Retrieve the current values for unchanged components
_Func->GetSphereColor(m_ID, &s_ColorB, &s_ColorG, NULL);
// Perform the requested operation
_Func->SetSphereColor(m_ID, s_ColorB, s_ColorG, b);
}
// ------------------------------------------------------------------------------------------------
static Object & Forcefield_CreateEx(CPlayer & player, Int32 world, Float32 x, Float32 y, Float32 z,
Uint8 r, Uint8 g, Uint8 b, Float32 radius)
{
return _Core->NewForcefield(player.GetID(), world, x, y, z, r, g, b, radius,
SQMOD_CREATE_DEFAULT, NullObject());
}
static Object & CreateForcefieldEx(CPlayer & player, Int32 world, Float32 x, Float32 y, Float32 z,
static Object & Forcefield_CreateEx(CPlayer & player, Int32 world, Float32 x, Float32 y, Float32 z,
Uint8 r, Uint8 g, Uint8 b, Float32 radius,
Int32 header, Object & payload)
{
@ -314,14 +403,14 @@ static Object & CreateForcefieldEx(CPlayer & player, Int32 world, Float32 x, Flo
}
// ------------------------------------------------------------------------------------------------
static Object & CreateForcefield(CPlayer & player, Int32 world, const Vector3 & pos,
static Object & Forcefield_Create(CPlayer & player, Int32 world, const Vector3 & pos,
const Color3 & color, Float32 radius)
{
return _Core->NewForcefield(player.GetID(), world, pos.x, pos.y, pos.z, color.r, color.g, color.b, radius,
SQMOD_CREATE_DEFAULT, NullObject());
}
static Object & CreateForcefield(CPlayer & player, Int32 world, const Vector3 & pos,
static Object & Forcefield_Create(CPlayer & player, Int32 world, const Vector3 & pos,
const Color3 & color, Float32 radius, Int32 header, Object & payload)
{
return _Core->NewForcefield(player.GetID(), world, pos.x, pos.y, pos.z, color.r, color.g, color.b, radius,
@ -333,22 +422,24 @@ void Register_CForcefield(HSQUIRRELVM vm)
{
RootTable(vm).Bind(_SC("SqForcefield"),
Class< CForcefield, NoConstructor< CForcefield > >(vm, _SC("SqForcefield"))
/* Metamethods */
// Metamethods
.Func(_SC("_cmp"), &CForcefield::Cmp)
.SquirrelFunc(_SC("_typename"), &CForcefield::Typename)
.Func(_SC("_tostring"), &CForcefield::ToString)
/* Core Properties */
// Static values
.SetStaticValue(_SC("MaxID"), CForcefield::Max)
// Core Properties
.Prop(_SC("ID"), &CForcefield::GetID)
.Prop(_SC("Tag"), &CForcefield::GetTag, &CForcefield::SetTag)
.Prop(_SC("Data"), &CForcefield::GetData, &CForcefield::SetData)
.Prop(_SC("MaxID"), &CForcefield::GetMaxID)
.Prop(_SC("Active"), &CForcefield::IsActive)
/* Core Functions */
// Core Functions
.Func(_SC("Bind"), &CForcefield::BindEvent)
/* Core Overloads */
// Core Overloads
.Overload< bool (CForcefield::*)(void) >(_SC("Destroy"), &CForcefield::Destroy)
.Overload< bool (CForcefield::*)(Int32) >(_SC("Destroy"), &CForcefield::Destroy)
.Overload< bool (CForcefield::*)(Int32, Object &) >(_SC("Destroy"), &CForcefield::Destroy)
/* Properties */
// Properties
.Prop(_SC("World"), &CForcefield::GetWorld, &CForcefield::SetWorld)
.Prop(_SC("Color"), &CForcefield::GetColor, &CForcefield::SetColor)
.Prop(_SC("Pos"), &CForcefield::GetPosition, &CForcefield::SetPosition)
@ -362,22 +453,21 @@ void Register_CForcefield(HSQUIRRELVM vm)
.Prop(_SC("R"), &CForcefield::GetColR, &CForcefield::SetColR)
.Prop(_SC("G"), &CForcefield::GetColG, &CForcefield::SetColG)
.Prop(_SC("B"), &CForcefield::GetColB, &CForcefield::SetColB)
/* Functions */
// Functions
.Func(_SC("StreamedFor"), &CForcefield::IsStreamedFor)
.Func(_SC("SetColor"), &CForcefield::SetColorEx)
.Func(_SC("SetPos"), &CForcefield::SetPositionEx)
.Func(_SC("SetPosition"), &CForcefield::SetPositionEx)
// Static Overloads
.StaticOverload< Object & (*)(CPlayer &, Int32, Float32, Float32, Float32, Uint8, Uint8, Uint8, Float32) >
(_SC("CreateEx"), &Forcefield_CreateEx)
.StaticOverload< Object & (*)(CPlayer &, Int32, Float32, Float32, Float32, Uint8, Uint8, Uint8, Float32, Int32, Object &) >
(_SC("CreateEx"), &Forcefield_CreateEx)
.StaticOverload< Object & (*)(CPlayer &, Int32, const Vector3 &, const Color3 &, Float32) >
(_SC("Create"), &Forcefield_Create)
.StaticOverload< Object & (*)(CPlayer &, Int32, const Vector3 &, const Color3 &, Float32, Int32, Object &) >
(_SC("Create"), &Forcefield_Create)
);
RootTable(vm)
.Overload< Object & (*)(CPlayer &, Int32, Float32, Float32, Float32, Uint8, Uint8, Uint8, Float32) >
(_SC("CreateForcefieldEx"), &CreateForcefieldEx)
.Overload< Object & (*)(CPlayer &, Int32, Float32, Float32, Float32, Uint8, Uint8, Uint8, Float32, Int32, Object &) >
(_SC("CreateForcefieldEx"), &CreateForcefieldEx)
.Overload< Object & (*)(CPlayer &, Int32, const Vector3 &, const Color3 &, Float32) >
(_SC("CreateForcefield"), &CreateForcefield)
.Overload< Object & (*)(CPlayer &, Int32, const Vector3 &, const Color3 &, Float32, Int32, Object &) >
(_SC("CreateForcefield"), &CreateForcefield);
}
} // Namespace:: SqMod
} // Namespace:: SqMod

View File

@ -8,7 +8,7 @@
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Manages Forcefield instances.
* Manages a single forcefield entity.
*/
class CForcefield
{
@ -24,20 +24,19 @@ private:
// --------------------------------------------------------------------------------------------
static Uint32 s_ColorR, s_ColorG, s_ColorB;
/* --------------------------------------------------------------------------------------------
* Cached identifiers for fast integer to string conversion.
*/
static SQChar s_StrID[SQMOD_FORCEFIELD_POOL][8];
/* --------------------------------------------------------------------------------------------
* Identifier of the managed entity.
*/
Int32 m_ID;
/* --------------------------------------------------------------------------------------------
* User tag and data associated with this instance.
* User tag associated with this instance.
*/
String m_Tag;
/* --------------------------------------------------------------------------------------------
* User data associated with this instance.
*/
Object m_Data;
/* --------------------------------------------------------------------------------------------
@ -45,20 +44,22 @@ private:
*/
CForcefield(Int32 id);
public:
/* --------------------------------------------------------------------------------------------
* Maximum possible number that could represent an identifier for this entity type.
*/
static const Int32 Max;
/* --------------------------------------------------------------------------------------------
* Copy constructor. (disabled)
*/
CForcefield(const CForcefield &);
CForcefield(const CForcefield &) = delete;
/* --------------------------------------------------------------------------------------------
* Copy assignment operator. (disabled)
* Move constructor. (disabled)
*/
CForcefield & operator = (const CForcefield &);
public:
// --------------------------------------------------------------------------------------------
static const Int32 Max;
CForcefield(CForcefield &&) = delete;
/* --------------------------------------------------------------------------------------------
* Destructor.
@ -66,14 +67,22 @@ public:
~CForcefield();
/* --------------------------------------------------------------------------------------------
* See whether this instance manages a valid entity.
* Copy assignment operator. (disabled)
*/
bool Validate() const
CForcefield & operator = (const CForcefield &) = delete;
/* --------------------------------------------------------------------------------------------
* Move assignment operator. (disabled)
*/
CForcefield & operator = (CForcefield &&) = delete;
/* --------------------------------------------------------------------------------------------
* See whether this instance manages a valid entity otherwise throw an exception.
*/
void Validate() const
{
if (VALID_ENTITY(m_ID))
return true;
SqThrow("Invalid forcefield reference [%s]", m_Tag.c_str());
return false;
if (INVALID_ENTITY(m_ID))
SqThrowF("Invalid forcefield reference [%s]", m_Tag.c_str());
}
/* --------------------------------------------------------------------------------------------
@ -84,27 +93,33 @@ public:
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
CSStr ToString() const;
const String & ToString() const;
/* --------------------------------------------------------------------------------------------
* Used by the script engine to retrieve the name from instances of this type.
*/
static SQInteger Typename(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Retrieve the identifier of the entity managed by this instance.
*/
Int32 GetID() const { return m_ID; }
/* --------------------------------------------------------------------------------------------
* Retrieve the maximum possible identifier to an entity of this type.
*/
Int32 GetMaxID() const { return SQMOD_FORCEFIELD_POOL; }
Int32 GetID() const
{
return m_ID;
}
/* --------------------------------------------------------------------------------------------
* Check whether this instance manages a valid entity.
*/
bool IsActive() const { return VALID_ENTITY(m_ID); }
bool IsActive() const
{
return VALID_ENTITY(m_ID);
}
/* --------------------------------------------------------------------------------------------
* Retrieve the associated user tag.
*/
CSStr GetTag() const;
const String & GetTag() const;
/* --------------------------------------------------------------------------------------------
* Modify the associated user tag.
@ -121,43 +136,155 @@ public:
*/
void SetData(Object & data);
// --------------------------------------------------------------------------------------------
/* --------------------------------------------------------------------------------------------
* Destroy the managed forcefield entity.
*/
bool Destroy()
{
return Destroy(0, NullObject());
}
/* --------------------------------------------------------------------------------------------
* Destroy the managed forcefield entity.
*/
bool Destroy(Int32 header)
{
return Destroy(header, NullObject());
}
/* --------------------------------------------------------------------------------------------
* Destroy the managed forcefield entity.
*/
bool Destroy(Int32 header, Object & payload);
bool Destroy() { return Destroy(0, NullObject()); }
bool Destroy(Int32 header) { return Destroy(header, NullObject()); }
// --------------------------------------------------------------------------------------------
bool BindEvent(Int32 evid, Object & env, Function & func) const;
/* --------------------------------------------------------------------------------------------
* Bind to an event supported by this entity type.
*/
void BindEvent(Int32 evid, Object & env, Function & func) const;
// --------------------------------------------------------------------------------------------
/* --------------------------------------------------------------------------------------------
* See if the managed forcefield entity is streamed for the specified player.
*/
bool IsStreamedFor(CPlayer & player) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the world in which the managed forcefield entity exists.
*/
Int32 GetWorld() const;
/* --------------------------------------------------------------------------------------------
* Modify the world in which the managed forcefield entity exists.
*/
void SetWorld(Int32 world) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the color of the managed forcefield entity.
*/
const Color3 & GetColor() const;
/* --------------------------------------------------------------------------------------------
* Modify the color of the managed forcefield entity.
*/
void SetColor(const Color3 & col) const;
/* --------------------------------------------------------------------------------------------
* Modify the color of the managed forcefield entity.
*/
void SetColorEx(Uint8 r, Uint8 g, Uint8 b) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the position of the managed forcefield entity.
*/
const Vector3 & GetPosition() const;
/* --------------------------------------------------------------------------------------------
* Modify the position of the managed forcefield entity.
*/
void SetPosition(const Vector3 & pos) const;
/* --------------------------------------------------------------------------------------------
* Modify the position of the managed forcefield entity.
*/
void SetPositionEx(Float32 x, Float32 y, Float32 z) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the radius of the managed forcefield entity.
*/
Float32 GetRadius() const;
/* --------------------------------------------------------------------------------------------
* Modify the radius of the managed forcefield entity.
*/
void SetRadius(Float32 radius) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the owner of the managed forcefield entity.
*/
Object & GetOwner() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the owner identifier of the managed forcefield entity.
*/
Int32 GetOwnerID() const;
// --------------------------------------------------------------------------------------------
/* --------------------------------------------------------------------------------------------
* Retrieve the position on the x axis of the managed forcefield entity.
*/
Float32 GetPosX() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the position on the y axis of the managed forcefield entity.
*/
Float32 GetPosY() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the position on the z axis of the managed forcefield entity.
*/
Float32 GetPosZ() const;
/* --------------------------------------------------------------------------------------------
* Modify the position on the x axis of the managed forcefield entity.
*/
void SetPosX(Float32 x) const;
/* --------------------------------------------------------------------------------------------
* Modify the position on the y axis of the managed forcefield entity.
*/
void SetPosY(Float32 y) const;
/* --------------------------------------------------------------------------------------------
* Modify the position on the z axis of the managed forcefield entity.
*/
void SetPosZ(Float32 z) const;
// --------------------------------------------------------------------------------------------
/* --------------------------------------------------------------------------------------------
* Retrieve the red color of the managed forcefield entity.
*/
Uint32 GetColR() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the green color of the managed forcefield entity.
*/
Uint32 GetColG() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the blue color of the managed forcefield entity.
*/
Uint32 GetColB() const;
/* --------------------------------------------------------------------------------------------
* Modify the red color of the managed forcefield entity.
*/
void SetColR(Uint32 r) const;
/* --------------------------------------------------------------------------------------------
* Modify the green color of the managed forcefield entity.
*/
void SetColG(Uint32 g) const;
/* --------------------------------------------------------------------------------------------
* Modify the blue color of the managed forcefield entity.
*/
void SetColB(Uint32 b) const;
};

View File

@ -6,15 +6,20 @@
namespace SqMod {
// ------------------------------------------------------------------------------------------------
SQChar CKeybind::s_StrID[SQMOD_KEYBIND_POOL][8];
const Int32 CKeybind::Max = SQMOD_KEYBIND_POOL;
// ------------------------------------------------------------------------------------------------
const Int32 CKeybind::Max = SQMOD_KEYBIND_POOL;
SQInteger CKeybind::Typename(HSQUIRRELVM vm)
{
static SQChar name[] = _SC("SqKeybind");
sq_pushstring(vm, name, sizeof(name));
return 1;
}
// ------------------------------------------------------------------------------------------------
CKeybind::CKeybind(Int32 id)
: m_ID(VALID_ENTITYGETEX(id, SQMOD_KEYBIND_POOL))
, m_Tag(VALID_ENTITY(m_ID) ? s_StrID[m_ID] : _SC("-1"))
, m_Tag(ToStrF("%d", id))
{
/* ... */
}
@ -36,108 +41,124 @@ Int32 CKeybind::Cmp(const CKeybind & o) const
return -1;
}
CSStr CKeybind::ToString() const
// ------------------------------------------------------------------------------------------------
const String & CKeybind::ToString() const
{
return VALID_ENTITYEX(m_ID, SQMOD_KEYBIND_POOL) ? s_StrID[m_ID] : _SC("-1");
return m_Tag;
}
// ------------------------------------------------------------------------------------------------
CSStr CKeybind::GetTag() const
const String & CKeybind::GetTag() const
{
return m_Tag.c_str();
return m_Tag;
}
// ------------------------------------------------------------------------------------------------
void CKeybind::SetTag(CSStr tag)
{
m_Tag.assign(tag);
}
// ------------------------------------------------------------------------------------------------
Object & CKeybind::GetData()
{
if (Validate())
return m_Data;
return NullObject();
// Validate the managed identifier
Validate();
// Return the requested information
return m_Data;
}
// ------------------------------------------------------------------------------------------------
void CKeybind::SetData(Object & data)
{
if (Validate())
m_Data = data;
// Validate the managed identifier
Validate();
// Apply the specified value
m_Data = data;
}
// ------------------------------------------------------------------------------------------------
bool CKeybind::Destroy(Int32 header, Object & payload)
{
// Validate the managed identifier
Validate();
// Perform the requested operation
return _Core->DelKeybind(m_ID, header, payload);
}
// ------------------------------------------------------------------------------------------------
bool CKeybind::BindEvent(Int32 evid, Object & env, Function & func) const
void CKeybind::BindEvent(Int32 evid, Object & env, Function & func) const
{
if (!Validate())
return false;
// Validate the managed identifier
Validate();
// Obtain the function instance called for this event
Function & event = _Core->GetKeybindEvent(m_ID, evid);
// Is the specified callback function null?
if (func.IsNull())
event.Release();
event.Release(); // Then release the current callback
// Assign the specified environment and function
else
event = Function(env.GetVM(), env, func.GetFunc());
return true;
}
// ------------------------------------------------------------------------------------------------
Int32 CKeybind::GetPrimary() const
Int32 CKeybind::GetFirst() const
{
if (Validate())
return _Core->GetKeybind(m_ID).mPrimary;
return -1;
// Validate the managed identifier
Validate();
// Return the requested information
return _Core->GetKeybind(m_ID).mFirst;
}
Int32 CKeybind::GetSecondary() const
// ------------------------------------------------------------------------------------------------
Int32 CKeybind::GetSecond() const
{
if (Validate())
return _Core->GetKeybind(m_ID).mSecondary;
return -1;
// Validate the managed identifier
Validate();
// Return the requested information
return _Core->GetKeybind(m_ID).mSecond;
}
Int32 CKeybind::GetAlternative() const
// ------------------------------------------------------------------------------------------------
Int32 CKeybind::GetThird() const
{
if (Validate())
return _Core->GetKeybind(m_ID).mAlternative;
return -1;
// Validate the managed identifier
Validate();
// Return the requested information
return _Core->GetKeybind(m_ID).mThird;
}
// ------------------------------------------------------------------------------------------------
bool CKeybind::IsRelease() const
{
if (Validate())
return _Core->GetKeybind(m_ID).mRelease;
return false;
// Validate the managed identifier
Validate();
// Return the requested information
return _Core->GetKeybind(m_ID).mRelease;
}
// ------------------------------------------------------------------------------------------------
static Object & CreateKeybindEx(Int32 slot, bool release, Int32 primary, Int32 secondary,
static Object & Keybind_CreateEx(Int32 slot, bool release, Int32 primary, Int32 secondary,
Int32 alternative)
{
return _Core->NewKeybind(slot, release, primary, secondary, alternative,
SQMOD_CREATE_DEFAULT, NullObject());
}
static Object & CreateKeybindEx(Int32 slot, bool release, Int32 primary, Int32 secondary,
static Object & Keybind_CreateEx(Int32 slot, bool release, Int32 primary, Int32 secondary,
Int32 alternative, Int32 header, Object & payload)
{
return _Core->NewKeybind(slot, release, primary, secondary, alternative, header, payload);
}
// ------------------------------------------------------------------------------------------------
static Object & CreateKeybind(bool release, Int32 primary, Int32 secondary, Int32 alternative)
static Object & Keybind_Create(bool release, Int32 primary, Int32 secondary, Int32 alternative)
{
return _Core->NewKeybind(-1, release, primary, secondary, alternative,
SQMOD_CREATE_DEFAULT, NullObject());
}
static Object & CreateKeybind(bool release, Int32 primary, Int32 secondary, Int32 alternative,
static Object & Keybind_Create(bool release, Int32 primary, Int32 secondary, Int32 alternative,
Int32 header, Object & payload)
{
return _Core->NewKeybind(-1, release, primary, secondary, alternative, header, payload);
@ -148,37 +169,38 @@ void Register_CKeybind(HSQUIRRELVM vm)
{
RootTable(vm).Bind(_SC("SqKeybind"),
Class< CKeybind, NoConstructor< CKeybind > >(vm, _SC("SqKeybind"))
/* Metamethods */
// Metamethods
.Func(_SC("_cmp"), &CKeybind::Cmp)
.SquirrelFunc(_SC("_typename"), &CKeybind::Typename)
.Func(_SC("_tostring"), &CKeybind::ToString)
/* Core Properties */
// Static values
.SetStaticValue(_SC("MaxID"), CKeybind::Max)
// Core Properties
.Prop(_SC("ID"), &CKeybind::GetID)
.Prop(_SC("Tag"), &CKeybind::GetTag, &CKeybind::SetTag)
.Prop(_SC("Data"), &CKeybind::GetData, &CKeybind::SetData)
.Prop(_SC("MaxID"), &CKeybind::GetMaxID)
.Prop(_SC("Active"), &CKeybind::IsActive)
/* Core Functions */
// Core Functions
.Func(_SC("Bind"), &CKeybind::BindEvent)
/* Core Overloads */
// Core Overloads
.Overload< bool (CKeybind::*)(void) >(_SC("Destroy"), &CKeybind::Destroy)
.Overload< bool (CKeybind::*)(Int32) >(_SC("Destroy"), &CKeybind::Destroy)
.Overload< bool (CKeybind::*)(Int32, Object &) >(_SC("Destroy"), &CKeybind::Destroy)
/* Properties */
.Prop(_SC("Primary"), &CKeybind::GetPrimary)
.Prop(_SC("Secondary"), &CKeybind::GetSecondary)
.Prop(_SC("Alternative"), &CKeybind::GetAlternative)
// Properties
.Prop(_SC("First"), &CKeybind::GetFirst)
.Prop(_SC("Second"), &CKeybind::GetSecond)
.Prop(_SC("Third"), &CKeybind::GetThird)
.Prop(_SC("Release"), &CKeybind::IsRelease)
// Static Overloads
.StaticOverload< Object & (*)(Int32, bool, Int32, Int32, Int32) >
(_SC("CreateEx"), &Keybind_CreateEx)
.StaticOverload< Object & (*)(Int32, bool, Int32, Int32, Int32, Int32, Object &) >
(_SC("CreateEx"), &Keybind_CreateEx)
.StaticOverload< Object & (*)(bool, Int32, Int32, Int32) >
(_SC("Create"), &Keybind_Create)
.StaticOverload< Object & (*)(bool, Int32, Int32, Int32, Int32, Object &) >
(_SC("Create"), &Keybind_Create)
);
RootTable(vm)
.Overload< Object & (*)(Int32, bool, Int32, Int32, Int32) >
(_SC("CreateKeybindEx"), &CreateKeybindEx)
.Overload< Object & (*)(Int32, bool, Int32, Int32, Int32, Int32, Object &) >
(_SC("CreateKeybindEx"), &CreateKeybindEx)
.Overload< Object & (*)(bool, Int32, Int32, Int32) >
(_SC("CreateKeybind"), &CreateKeybind)
.Overload< Object & (*)(bool, Int32, Int32, Int32, Int32, Object &) >
(_SC("CreateKeybind"), &CreateKeybind);
}
} // Namespace:: SqMod

View File

@ -8,7 +8,7 @@
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Manages Keybind instances.
* Manages a single keybind entity.
*/
class CKeybind
{
@ -17,20 +17,19 @@ class CKeybind
private:
/* --------------------------------------------------------------------------------------------
* Cached identifiers for fast integer to string conversion.
*/
static SQChar s_StrID[SQMOD_KEYBIND_POOL][8];
/* --------------------------------------------------------------------------------------------
* Identifier of the managed entity.
*/
Int32 m_ID;
/* --------------------------------------------------------------------------------------------
* User tag and data associated with this instance.
* User tag associated with this instance.
*/
String m_Tag;
/* --------------------------------------------------------------------------------------------
* User data associated with this instance.
*/
Object m_Data;
/* --------------------------------------------------------------------------------------------
@ -38,20 +37,22 @@ private:
*/
CKeybind(Int32 id);
public:
/* --------------------------------------------------------------------------------------------
* Maximum possible number that could represent an identifier for this entity type.
*/
static const Int32 Max;
/* --------------------------------------------------------------------------------------------
* Copy constructor. (disabled)
*/
CKeybind(const CKeybind &);
CKeybind(const CKeybind &) = delete;
/* --------------------------------------------------------------------------------------------
* Copy assignment operator. (disabled)
* Move constructor. (disabled)
*/
CKeybind & operator = (const CKeybind &);
public:
// --------------------------------------------------------------------------------------------
static const Int32 Max;
CKeybind(CKeybind &&) = delete;
/* --------------------------------------------------------------------------------------------
* Destructor.
@ -59,14 +60,22 @@ public:
~CKeybind();
/* --------------------------------------------------------------------------------------------
* See whether this instance manages a valid entity.
* Copy assignment operator. (disabled)
*/
bool Validate() const
CKeybind & operator = (const CKeybind &) = delete;
/* --------------------------------------------------------------------------------------------
* Move assignment operator. (disabled)
*/
CKeybind & operator = (CKeybind &&) = delete;
/* --------------------------------------------------------------------------------------------
* See whether this instance manages a valid entity instance otherwise throw an exception.
*/
void Validate() const
{
if (VALID_ENTITY(m_ID))
return true;
SqThrow("Invalid keybind reference [%s]", m_Tag.c_str());
return false;
if (INVALID_ENTITY(m_ID))
SqThrowF("Invalid keybind reference [%s]", m_Tag.c_str());
}
/* --------------------------------------------------------------------------------------------
@ -77,27 +86,33 @@ public:
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
CSStr ToString() const;
const String & ToString() const;
/* --------------------------------------------------------------------------------------------
* Used by the script engine to retrieve the name from instances of this type.
*/
static SQInteger Typename(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Retrieve the identifier of the entity managed by this instance.
*/
Int32 GetID() const { return m_ID; }
/* --------------------------------------------------------------------------------------------
* Retrieve the maximum possible identifier to an entity of this type.
*/
Int32 GetMaxID() const { return SQMOD_KEYBIND_POOL; }
Int32 GetID() const
{
return m_ID;
}
/* --------------------------------------------------------------------------------------------
* Check whether this instance manages a valid entity.
*/
bool IsActive() const { return VALID_ENTITY(m_ID); }
bool IsActive() const
{
return VALID_ENTITY(m_ID);
}
/* --------------------------------------------------------------------------------------------
* Retrieve the associated user tag.
*/
CSStr GetTag() const;
const String & GetTag() const;
/* --------------------------------------------------------------------------------------------
* Modify the associated user tag.
@ -114,18 +129,50 @@ public:
*/
void SetData(Object & data);
// --------------------------------------------------------------------------------------------
/* --------------------------------------------------------------------------------------------
* Destroy the managed destroy entity.
*/
bool Destroy()
{
return Destroy(0, NullObject());
}
/* --------------------------------------------------------------------------------------------
* Destroy the managed destroy entity.
*/
bool Destroy(Int32 header)
{
return Destroy(header, NullObject());
}
/* --------------------------------------------------------------------------------------------
* Destroy the managed destroy entity.
*/
bool Destroy(Int32 header, Object & payload);
bool Destroy() { return Destroy(0, NullObject()); }
bool Destroy(Int32 header) { return Destroy(header, NullObject()); }
// --------------------------------------------------------------------------------------------
bool BindEvent(Int32 evid, Object & env, Function & func) const;
/* --------------------------------------------------------------------------------------------
* Bind to an event supported by this entity type.
*/
void BindEvent(Int32 evid, Object & env, Function & func) const;
// --------------------------------------------------------------------------------------------
Int32 GetPrimary() const;
Int32 GetSecondary() const;
Int32 GetAlternative() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the first key code of the managed keybind entity.
*/
Int32 GetFirst() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the second key code of the managed keybind entity.
*/
Int32 GetSecond() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the third key code of the managed keybind entity.
*/
Int32 GetThird() const;
/* --------------------------------------------------------------------------------------------
* See whether the managed keybind entity reacts to key release events.
*/
bool IsRelease() const;
};

View File

@ -13,15 +13,20 @@ Vector3 CObject::s_Vector3;
Quaternion CObject::s_Quaternion;
// ------------------------------------------------------------------------------------------------
SQChar CObject::s_StrID[SQMOD_OBJECT_POOL][8];
const Int32 CObject::Max = SQMOD_OBJECT_POOL;
// ------------------------------------------------------------------------------------------------
const Int32 CObject::Max = SQMOD_OBJECT_POOL;
SQInteger CObject::Typename(HSQUIRRELVM vm)
{
static SQChar name[] = _SC("SqObject");
sq_pushstring(vm, name, sizeof(name));
return 1;
}
// ------------------------------------------------------------------------------------------------
CObject::CObject(Int32 id)
: m_ID(VALID_ENTITYGETEX(id, SQMOD_OBJECT_POOL))
, m_Tag(VALID_ENTITY(m_ID) ? s_StrID[m_ID] : _SC("-1"))
, m_Tag(ToStrF("%d", id))
{
/* ... */
}
@ -43,372 +48,517 @@ Int32 CObject::Cmp(const CObject & o) const
return -1;
}
CSStr CObject::ToString() const
// ------------------------------------------------------------------------------------------------
const String & CObject::ToString() const
{
return VALID_ENTITYEX(m_ID, SQMOD_OBJECT_POOL) ? s_StrID[m_ID] : _SC("-1");
return m_Tag;
}
// ------------------------------------------------------------------------------------------------
CSStr CObject::GetTag() const
const String & CObject::GetTag() const
{
return m_Tag.c_str();
return m_Tag;
}
// ------------------------------------------------------------------------------------------------
void CObject::SetTag(CSStr tag)
{
m_Tag.assign(tag);
}
// ------------------------------------------------------------------------------------------------
Object & CObject::GetData()
{
if (Validate())
return m_Data;
return NullObject();
// Validate the managed identifier
Validate();
// Return the requested information
return m_Data;
}
// ------------------------------------------------------------------------------------------------
void CObject::SetData(Object & data)
{
if (Validate())
m_Data = data;
// Validate the managed identifier
Validate();
// Apply the specified value
m_Data = data;
}
// ------------------------------------------------------------------------------------------------
bool CObject::Destroy(Int32 header, Object & payload)
{
// Validate the managed identifier
Validate();
// Perform the requested operation
return _Core->DelObject(m_ID, header, payload);
}
// ------------------------------------------------------------------------------------------------
bool CObject::BindEvent(Int32 evid, Object & env, Function & func) const
void CObject::BindEvent(Int32 evid, Object & env, Function & func) const
{
if (!Validate())
return false;
// Validate the managed identifier
Validate();
// Obtain the function instance called for this event
Function & event = _Core->GetObjectEvent(m_ID, evid);
// Is the specified callback function null?
if (func.IsNull())
event.Release();
event.Release(); // Then release the current callback
// Assign the specified environment and function
else
event = Function(env.GetVM(), env, func.GetFunc());
return true;
}
// ------------------------------------------------------------------------------------------------
bool CObject::IsStreamedFor(CPlayer & player) const
{
// Is the specified player even valid?
if (!player.IsActive())
SqThrow("Invalid player argument: null");
else if (Validate())
return _Func->IsObjectStreamedForPlayer(m_ID, player.GetID());
return false;
SqThrowF("Invalid player argument: null");
// Validate the managed identifier
Validate();
// Return the requested information
return _Func->IsObjectStreamedForPlayer(m_ID, player.GetID());
}
// ------------------------------------------------------------------------------------------------
Int32 CObject::GetModel() const
{
if (Validate())
return _Func->GetObjectModel(m_ID);
return -1;
// Validate the managed identifier
Validate();
// Return the requested information
return _Func->GetObjectModel(m_ID);
}
// ------------------------------------------------------------------------------------------------
Int32 CObject::GetWorld() const
{
if (Validate())
return _Func->GetObjectWorld(m_ID);
return -1;
// Validate the managed identifier
Validate();
// Return the requested information
return _Func->GetObjectWorld(m_ID);
}
// ------------------------------------------------------------------------------------------------
void CObject::SetWorld(Int32 world) const
{
if (Validate())
_Func->SetObjectWorld(m_ID, world);
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->SetObjectWorld(m_ID, world);
}
// ------------------------------------------------------------------------------------------------
Int32 CObject::GetAlpha() const
{
if (Validate())
return _Func->GetObjectAlpha(m_ID);
return -1;
// Validate the managed identifier
Validate();
// Return the requested information
return _Func->GetObjectAlpha(m_ID);
}
// ------------------------------------------------------------------------------------------------
void CObject::SetAlpha(Int32 alpha) const
{
if (Validate())
_Func->SetObjectAlpha(m_ID, alpha, 0);
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->SetObjectAlpha(m_ID, alpha, 0);
}
// ------------------------------------------------------------------------------------------------
void CObject::SetAlphaEx(Int32 alpha, Int32 time) const
{
if (Validate())
_Func->SetObjectAlpha(m_ID, alpha, time);
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->SetObjectAlpha(m_ID, alpha, time);
}
// ------------------------------------------------------------------------------------------------
void CObject::MoveTo(const Vector3 & pos, Int32 time) const
{
if (Validate())
_Func->MoveObjectTo(m_ID, pos.x, pos.y, pos.z, time);
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->MoveObjectTo(m_ID, pos.x, pos.y, pos.z, time);
}
// ------------------------------------------------------------------------------------------------
void CObject::MoveToEx(Float32 x, Float32 y, Float32 z, Int32 time) const
{
if (Validate())
_Func->MoveObjectTo(m_ID, x, y, z, time);
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->MoveObjectTo(m_ID, x, y, z, time);
}
// ------------------------------------------------------------------------------------------------
void CObject::MoveBy(const Vector3 & pos, Int32 time) const
{
if (Validate())
_Func->MoveObjectBy(m_ID, pos.x, pos.y, pos.z, time);
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->MoveObjectBy(m_ID, pos.x, pos.y, pos.z, time);
}
// ------------------------------------------------------------------------------------------------
void CObject::MoveByEx(Float32 x, Float32 y, Float32 z, Int32 time) const
{
if (Validate())
_Func->MoveObjectBy(m_ID, x, y, z, time);
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->MoveObjectBy(m_ID, x, y, z, time);
}
// ------------------------------------------------------------------------------------------------
const Vector3 & CObject::GetPosition()
{
// Validate the managed identifier
Validate();
// Clear previous position information
s_Vector3.Clear();
if (Validate())
_Func->GetObjectPos(m_ID, &s_Vector3.x, &s_Vector3.y, &s_Vector3.z);
// Query the server for the position values
_Func->GetObjectPos(m_ID, &s_Vector3.x, &s_Vector3.y, &s_Vector3.z);
// Return the requested information
return s_Vector3;
}
// ------------------------------------------------------------------------------------------------
void CObject::SetPosition(const Vector3 & pos) const
{
if (Validate())
_Func->SetObjectPos(m_ID, pos.x, pos.y, pos.z);
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->SetObjectPos(m_ID, pos.x, pos.y, pos.z);
}
// ------------------------------------------------------------------------------------------------
void CObject::SetPositionEx(Float32 x, Float32 y, Float32 z) const
{
if (Validate())
_Func->SetObjectPos(m_ID, x, y, z);
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->SetObjectPos(m_ID, x, y, z);
}
// ------------------------------------------------------------------------------------------------
void CObject::RotateTo(const Quaternion & rot, Int32 time) const
{
if (Validate())
_Func->RotObjectTo(m_ID, rot.x, rot.y, rot.z, rot.w, time);
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->RotObjectTo(m_ID, rot.x, rot.y, rot.z, rot.w, time);
}
// ------------------------------------------------------------------------------------------------
void CObject::RotateToEx(Float32 x, Float32 y, Float32 z, Float32 w, Int32 time) const
{
if (Validate())
_Func->RotObjectTo(m_ID, x, y, z, w, time);
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->RotObjectTo(m_ID, x, y, z, w, time);
}
// ------------------------------------------------------------------------------------------------
void CObject::RotateToEuler(const Vector3 & rot, Int32 time) const
{
if (Validate())
_Func->RotObjectToEuler(m_ID, rot.x, rot.y, rot.z, time);
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->RotObjectToEuler(m_ID, rot.x, rot.y, rot.z, time);
}
// ------------------------------------------------------------------------------------------------
void CObject::RotateToEulerEx(Float32 x, Float32 y, Float32 z, Int32 time) const
{
if (Validate())
_Func->RotObjectToEuler(m_ID, x, y, z, time);
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->RotObjectToEuler(m_ID, x, y, z, time);
}
// ------------------------------------------------------------------------------------------------
void CObject::RotateBy(const Quaternion & rot, Int32 time) const
{
if (Validate())
_Func->RotObjectBy(m_ID, rot.x, rot.y, rot.z, rot.w, time);
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->RotObjectBy(m_ID, rot.x, rot.y, rot.z, rot.w, time);
}
// ------------------------------------------------------------------------------------------------
void CObject::RotateByEx(Float32 x, Float32 y, Float32 z, Float32 w, Int32 time) const
{
if (Validate())
_Func->RotObjectBy(m_ID, x, y, z, w, time);
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->RotObjectBy(m_ID, x, y, z, w, time);
}
// ------------------------------------------------------------------------------------------------
void CObject::RotateByEuler(const Vector3 & rot, Int32 time) const
{
if (Validate())
_Func->RotObjectByEuler(m_ID, rot.x, rot.y, rot.z, time);
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->RotObjectByEuler(m_ID, rot.x, rot.y, rot.z, time);
}
// ------------------------------------------------------------------------------------------------
void CObject::RotateByEulerEx(Float32 x, Float32 y, Float32 z, Int32 time) const
{
if (Validate())
_Func->RotObjectByEuler(m_ID, x, y, z, time);
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->RotObjectByEuler(m_ID, x, y, z, time);
}
// ------------------------------------------------------------------------------------------------
const Quaternion & CObject::GetRotation()
{
// Validate the managed identifier
Validate();
// Clear previous rotation information
s_Quaternion.Clear();
if (Validate())
_Func->GetObjectRot(m_ID, &s_Quaternion.x, &s_Quaternion.y, &s_Quaternion.z, &s_Quaternion.w);
// Query the server for the rotation values
_Func->GetObjectRot(m_ID, &s_Quaternion.x, &s_Quaternion.y, &s_Quaternion.z, &s_Quaternion.w);
// Return the requested information
return s_Quaternion;
}
// ------------------------------------------------------------------------------------------------
const Vector3 & CObject::GetRotationEuler()
{
// Validate the managed identifier
Validate();
// Clear previous rotation information
s_Vector3.Clear();
if (Validate())
_Func->GetObjectRotEuler(m_ID, &s_Vector3.x, &s_Vector3.y, &s_Vector3.z);
// Query the server for the rotation values
_Func->GetObjectRotEuler(m_ID, &s_Vector3.x, &s_Vector3.y, &s_Vector3.z);
// Return the requested information
return s_Vector3;
}
// ------------------------------------------------------------------------------------------------
bool CObject::GetShotReport() const
{
if (Validate())
return _Func->IsObjectShotReport(m_ID);
return false;
// Validate the managed identifier
Validate();
// Return the requested information
return _Func->IsObjectShotReport(m_ID);
}
// ------------------------------------------------------------------------------------------------
void CObject::SetShotReport(bool toggle) const
{
if (Validate())
_Func->SetObjectShotReport(m_ID, toggle);
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->SetObjectShotReport(m_ID, toggle);
}
// ------------------------------------------------------------------------------------------------
bool CObject::GetBumpReport() const
{
if (Validate())
return _Func->IsObjectBumpReport(m_ID);
return false;
// Validate the managed identifier
Validate();
// Return the requested information
return _Func->IsObjectBumpReport(m_ID);
}
// ------------------------------------------------------------------------------------------------
void CObject::SetBumpReport(bool toggle) const
{
if (Validate())
_Func->SetObjectBumpReport(m_ID, toggle);
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->SetObjectBumpReport(m_ID, toggle);
}
// ------------------------------------------------------------------------------------------------
Float32 CObject::GetPosX() const
{
// Validate the managed identifier
Validate();
// Clear previous position information, if any
s_Vector3.x = 0;
if (Validate())
_Func->GetObjectPos(m_ID, &s_Vector3.x, NULL, NULL);
// Query the server for the requested component value
_Func->GetObjectPos(m_ID, &s_Vector3.x, NULL, NULL);
// Return the requested information
return s_Vector3.x;
}
// ------------------------------------------------------------------------------------------------
Float32 CObject::GetPosY() const
{
// Validate the managed identifier
Validate();
// Clear previous position information, if any
s_Vector3.y = 0;
if (Validate())
_Func->GetObjectPos(m_ID, NULL, &s_Vector3.y, NULL);
// Query the server for the requested component value
_Func->GetObjectPos(m_ID, NULL, &s_Vector3.y, NULL);
// Return the requested information
return s_Vector3.y;
}
// ------------------------------------------------------------------------------------------------
Float32 CObject::GetPosZ() const
{
// Validate the managed identifier
Validate();
// Clear previous position information, if any
s_Vector3.z = 0;
if (Validate())
_Func->GetObjectPos(m_ID, NULL, NULL, &s_Vector3.z);
// Query the server for the requested component value
_Func->GetObjectPos(m_ID, NULL, NULL, &s_Vector3.z);
// Return the requested information
return s_Vector3.z;
}
// ------------------------------------------------------------------------------------------------
void CObject::SetPosX(Float32 x) const
{
if (Validate())
{
_Func->GetObjectPos(m_ID, NULL, &s_Vector3.y, &s_Vector3.z);
_Func->SetObjectPos(m_ID, x, s_Vector3.y, s_Vector3.z);
}
// Validate the managed identifier
Validate();
// Retrieve the current values for unchanged components
_Func->GetObjectPos(m_ID, NULL, &s_Vector3.y, &s_Vector3.z);
// Perform the requested operation
_Func->SetObjectPos(m_ID, x, s_Vector3.y, s_Vector3.z);
}
// ------------------------------------------------------------------------------------------------
void CObject::SetPosY(Float32 y) const
{
if (Validate())
{
_Func->GetObjectPos(m_ID, &s_Vector3.x, NULL, &s_Vector3.z);
_Func->SetObjectPos(m_ID, s_Vector3.x, y, s_Vector3.z);
}
// Validate the managed identifier
Validate();
// Retrieve the current values for unchanged components
_Func->GetObjectPos(m_ID, &s_Vector3.x, NULL, &s_Vector3.z);
// Perform the requested operation
_Func->SetObjectPos(m_ID, s_Vector3.x, y, s_Vector3.z);
}
// ------------------------------------------------------------------------------------------------
void CObject::SetPosZ(Float32 z) const
{
if (Validate())
{
_Func->GetObjectPos(m_ID, &s_Vector3.x, &s_Vector3.y, NULL);
_Func->SetObjectPos(m_ID, s_Vector3.z, s_Vector3.y, z);
}
// Validate the managed identifier
Validate();
// Retrieve the current values for unchanged components
_Func->GetObjectPos(m_ID, &s_Vector3.x, &s_Vector3.y, NULL);
// Perform the requested operation
_Func->SetObjectPos(m_ID, s_Vector3.z, s_Vector3.y, z);
}
// ------------------------------------------------------------------------------------------------
Float32 CObject::GetRotX() const
{
// Validate the managed identifier
Validate();
// Clear previous rotation information, if any
s_Quaternion.x = 0;
if (Validate())
_Func->GetObjectRot(m_ID, &s_Quaternion.x, NULL, NULL, NULL);
// Query the server for the requested component value
_Func->GetObjectRot(m_ID, &s_Quaternion.x, NULL, NULL, NULL);
// Return the requested information
return s_Quaternion.x;
}
// ------------------------------------------------------------------------------------------------
Float32 CObject::GetRotY() const
{
// Validate the managed identifier
Validate();
// Clear previous rotation information, if any
s_Quaternion.y = 0;
if (Validate())
_Func->GetObjectRot(m_ID, NULL, &s_Quaternion.y, NULL, NULL);
// Query the server for the requested component value
_Func->GetObjectRot(m_ID, NULL, &s_Quaternion.y, NULL, NULL);
// Return the requested information
return s_Quaternion.y;
}
// ------------------------------------------------------------------------------------------------
Float32 CObject::GetRotZ() const
{
// Validate the managed identifier
Validate();
// Clear previous rotation information, if any
s_Quaternion.z = 0;
if (Validate())
_Func->GetObjectRot(m_ID, NULL, NULL, &s_Quaternion.z, NULL);
// Query the server for the requested component value
_Func->GetObjectRot(m_ID, NULL, NULL, &s_Quaternion.z, NULL);
// Return the requested information
return s_Quaternion.z;
}
// ------------------------------------------------------------------------------------------------
Float32 CObject::GetRotW() const
{
// Validate the managed identifier
Validate();
// Clear previous rotation information, if any
s_Quaternion.w = 0;
if (Validate())
_Func->GetObjectRot(m_ID, NULL, NULL, NULL, &s_Quaternion.w);
// Query the server for the requested component value
_Func->GetObjectRot(m_ID, NULL, NULL, NULL, &s_Quaternion.w);
// Return the requested information
return s_Quaternion.w;
}
// ------------------------------------------------------------------------------------------------
Float32 CObject::GetERotX() const
{
// Validate the managed identifier
Validate();
// Clear previous rotation information, if any
s_Vector3.x = 0;
if (Validate())
_Func->GetObjectRotEuler(m_ID, &s_Vector3.x, NULL, NULL);
// Query the server for the requested component value
_Func->GetObjectRotEuler(m_ID, &s_Vector3.x, NULL, NULL);
// Return the requested information
return s_Vector3.x;
}
// ------------------------------------------------------------------------------------------------
Float32 CObject::GetERotY() const
{
// Validate the managed identifier
Validate();
// Clear previous rotation information, if any
s_Vector3.y = 0;
if (Validate())
_Func->GetObjectRotEuler(m_ID, NULL, &s_Vector3.y, NULL);
// Query the server for the requested component value
_Func->GetObjectRotEuler(m_ID, NULL, &s_Vector3.y, NULL);
// Return the requested information
return s_Vector3.y;
}
// ------------------------------------------------------------------------------------------------
Float32 CObject::GetERotZ() const
{
// Validate the managed identifier
Validate();
// Clear previous rotation information, if any
s_Vector3.z = 0;
if (Validate())
_Func->GetObjectRotEuler(m_ID, NULL, NULL, &s_Vector3.z);
// Query the server for the requested component value
_Func->GetObjectRotEuler(m_ID, NULL, NULL, &s_Vector3.z);
// Return the requested information
return s_Vector3.z;
}
// ------------------------------------------------------------------------------------------------
static Object & CreateObjectEx(Int32 model, Int32 world, Float32 x, Float32 y, Float32 z,
static Object & Object_CreateEx(Int32 model, Int32 world, Float32 x, Float32 y, Float32 z,
Int32 alpha)
{
return _Core->NewObject(model, world, x, y, z, alpha, SQMOD_CREATE_DEFAULT, NullObject());
}
static Object & CreateObjectEx(Int32 model, Int32 world, Float32 x, Float32 y, Float32 z,
static Object & Object_CreateEx(Int32 model, Int32 world, Float32 x, Float32 y, Float32 z,
Int32 alpha, Int32 header, Object & payload)
{
return _Core->NewObject(model, world, x, y, z, alpha, header, payload);
}
// ------------------------------------------------------------------------------------------------
static Object & CreateObject(Int32 model, Int32 world, const Vector3 & pos, Int32 alpha)
static Object & Object_Create(Int32 model, Int32 world, const Vector3 & pos, Int32 alpha)
{
return _Core->NewObject(model, world, pos.x, pos.y, pos.z, alpha,
SQMOD_CREATE_DEFAULT, NullObject());
}
static Object & CreateObject(Int32 model, Int32 world, const Vector3 & pos, Int32 alpha,
static Object & Object_Create(Int32 model, Int32 world, const Vector3 & pos, Int32 alpha,
Int32 header, Object & payload)
{
return _Core->NewObject(model, world, pos.x, pos.y, pos.z, alpha, header, payload);
@ -419,22 +569,24 @@ void Register_CObject(HSQUIRRELVM vm)
{
RootTable(vm).Bind(_SC("SqObject"),
Class< CObject, NoConstructor< CObject > >(vm, _SC("SqObject"))
/* Metamethods */
// Metamethods
.Func(_SC("_cmp"), &CObject::Cmp)
.SquirrelFunc(_SC("_typename"), &CObject::Typename)
.Func(_SC("_tostring"), &CObject::ToString)
/* Core Properties */
// Static values
.SetStaticValue(_SC("MaxID"), CObject::Max)
// Core Properties
.Prop(_SC("ID"), &CObject::GetID)
.Prop(_SC("Tag"), &CObject::GetTag, &CObject::SetTag)
.Prop(_SC("Data"), &CObject::GetData, &CObject::SetData)
.Prop(_SC("MaxID"), &CObject::GetMaxID)
.Prop(_SC("Active"), &CObject::IsActive)
/* Core Functions */
// Core Functions
.Func(_SC("Bind"), &CObject::BindEvent)
/* Core Overloads */
// Core Overloads
.Overload< bool (CObject::*)(void) >(_SC("Destroy"), &CObject::Destroy)
.Overload< bool (CObject::*)(Int32) >(_SC("Destroy"), &CObject::Destroy)
.Overload< bool (CObject::*)(Int32, Object &) >(_SC("Destroy"), &CObject::Destroy)
/* Properties */
// Properties
.Prop(_SC("Model"), &CObject::GetModel)
.Prop(_SC("World"), &CObject::GetWorld, &CObject::SetWorld)
.Prop(_SC("Alpha"), &CObject::GetAlpha, &CObject::SetAlpha)
@ -455,11 +607,11 @@ void Register_CObject(HSQUIRRELVM vm)
.Prop(_SC("EX"), &CObject::GetERotX)
.Prop(_SC("EY"), &CObject::GetERotY)
.Prop(_SC("EZ"), &CObject::GetERotZ)
/* Functions */
// Functions
.Func(_SC("StreamedFor"), &CObject::IsStreamedFor)
.Func(_SC("SetAlpha"), &CObject::SetAlphaEx)
.Func(_SC("SetPosition"), &CObject::SetPositionEx)
/* Overloads */
// Overloads
.Overload< void (CObject::*)(const Vector3 &, Int32) const >
(_SC("MoveTo"), &CObject::MoveTo)
.Overload< void (CObject::*)(Float32, Float32, Float32, Int32) const >
@ -484,17 +636,16 @@ void Register_CObject(HSQUIRRELVM vm)
(_SC("RotateByEuler"), &CObject::RotateByEuler)
.Overload< void (CObject::*)(Float32, Float32, Float32, Int32) const >
(_SC("RotateByEuler"), &CObject::RotateByEulerEx)
// Static Overloads
.StaticOverload< Object & (*)(Int32, Int32, Float32, Float32, Float32, Int32) >
(_SC("CreateEx"), &Object_CreateEx)
.StaticOverload< Object & (*)(Int32, Int32, Float32, Float32, Float32, Int32, Int32, Object &) >
(_SC("CreateEx"), &Object_CreateEx)
.StaticOverload< Object & (*)(Int32, Int32, const Vector3 &, Int32) >
(_SC("Create"), &Object_Create)
.StaticOverload< Object & (*)(Int32, Int32, const Vector3 &, Int32, Int32, Object &) >
(_SC("Create"), &Object_Create)
);
RootTable(vm)
.Overload< Object & (*)(Int32, Int32, Float32, Float32, Float32, Int32) >
(_SC("CreateObjectEx"), &CreateObjectEx)
.Overload< Object & (*)(Int32, Int32, Float32, Float32, Float32, Int32, Int32, Object &) >
(_SC("CreateObjectEx"), &CreateObjectEx)
.Overload< Object & (*)(Int32, Int32, const Vector3 &, Int32) >
(_SC("CreateObject"), &CreateObject)
.Overload< Object & (*)(Int32, Int32, const Vector3 &, Int32, Int32, Object &) >
(_SC("CreateObject"), &CreateObject);
}
} // Namespace:: SqMod
} // Namespace:: SqMod

View File

@ -8,7 +8,7 @@
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Manages Object instances.
* Manages a single object entity.
*/
class CObject
{
@ -21,20 +21,19 @@ private:
static Vector3 s_Vector3;
static Quaternion s_Quaternion;
/* --------------------------------------------------------------------------------------------
* Cached identifiers for fast integer to string conversion.
*/
static SQChar s_StrID[SQMOD_OBJECT_POOL][8];
/* --------------------------------------------------------------------------------------------
* Identifier of the managed entity.
*/
Int32 m_ID;
/* --------------------------------------------------------------------------------------------
* User tag and data associated with this instance.
* User tag associated with this instance.
*/
String m_Tag;
/* --------------------------------------------------------------------------------------------
* User data associated with this instance.
*/
Object m_Data;
/* --------------------------------------------------------------------------------------------
@ -42,20 +41,22 @@ private:
*/
CObject(Int32 id);
public:
/* --------------------------------------------------------------------------------------------
* Maximum possible number that could represent an identifier for this entity type.
*/
static const Int32 Max;
/* --------------------------------------------------------------------------------------------
* Copy constructor. (disabled)
*/
CObject(const CObject &);
CObject(const CObject &) = delete;
/* --------------------------------------------------------------------------------------------
* Copy assignment operator. (disabled)
* Move constructor. (disabled)
*/
CObject & operator = (const CObject &);
public:
// --------------------------------------------------------------------------------------------
static const Int32 Max;
CObject(CObject &&) = delete;
/* --------------------------------------------------------------------------------------------
* Destructor.
@ -63,14 +64,22 @@ public:
~CObject();
/* --------------------------------------------------------------------------------------------
* See whether this instance manages a valid entity.
* Copy assignment operator. (disabled)
*/
bool Validate() const
CObject & operator = (const CObject &) = delete;
/* --------------------------------------------------------------------------------------------
* Move assignment operator. (disabled)
*/
CObject & operator = (CObject &&) = delete;
/* --------------------------------------------------------------------------------------------
* See whether this instance manages a valid entity instance otherwise throw an exception.
*/
void Validate() const
{
if (VALID_ENTITY(m_ID))
return true;
SqThrow("Invalid object reference [%s]", m_Tag.c_str());
return false;
if (INVALID_ENTITY(m_ID))
SqThrowF("Invalid object reference [%s]", m_Tag.c_str());
}
/* --------------------------------------------------------------------------------------------
@ -81,27 +90,33 @@ public:
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
CSStr ToString() const;
const String & ToString() const;
/* --------------------------------------------------------------------------------------------
* Used by the script engine to retrieve the name from instances of this type.
*/
static SQInteger Typename(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Retrieve the identifier of the entity managed by this instance.
*/
Int32 GetID() const { return m_ID; }
/* --------------------------------------------------------------------------------------------
* Retrieve the maximum possible identifier to an entity of this type.
*/
Int32 GetMaxID() const { return SQMOD_OBJECT_POOL; }
Int32 GetID() const
{
return m_ID;
}
/* --------------------------------------------------------------------------------------------
* Check whether this instance manages a valid entity.
*/
bool IsActive() const { return VALID_ENTITY(m_ID); }
bool IsActive() const
{
return VALID_ENTITY(m_ID);
}
/* --------------------------------------------------------------------------------------------
* Retrieve the associated user tag.
*/
CSStr GetTag() const;
const String & GetTag() const;
/* --------------------------------------------------------------------------------------------
* Modify the associated user tag.
@ -118,59 +133,235 @@ public:
*/
void SetData(Object & data);
// --------------------------------------------------------------------------------------------
/* --------------------------------------------------------------------------------------------
* Destroy the managed object entity.
*/
bool Destroy()
{
return Destroy(0, NullObject());
}
/* --------------------------------------------------------------------------------------------
* Destroy the managed object entity.
*/
bool Destroy(Int32 header)
{
return Destroy(header, NullObject());
}
/* --------------------------------------------------------------------------------------------
* Destroy the managed object entity.
*/
bool Destroy(Int32 header, Object & payload);
bool Destroy() { return Destroy(0, NullObject()); }
bool Destroy(Int32 header) { return Destroy(header, NullObject()); }
// --------------------------------------------------------------------------------------------
bool BindEvent(Int32 evid, Object & env, Function & func) const;
/* --------------------------------------------------------------------------------------------
* Bind to an event supported by this entity type.
*/
void BindEvent(Int32 evid, Object & env, Function & func) const;
// --------------------------------------------------------------------------------------------
/* --------------------------------------------------------------------------------------------
* See if the managed object entity is streamed for the specified player.
*/
bool IsStreamedFor(CPlayer & player) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the model of the managed object entity.
*/
Int32 GetModel() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the world in which the managed object entity exists.
*/
Int32 GetWorld() const;
/* --------------------------------------------------------------------------------------------
* Modify the world in which the managed object entity exists.
*/
void SetWorld(Int32 world) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the alpha of the managed object entity.
*/
Int32 GetAlpha() const;
/* --------------------------------------------------------------------------------------------
* Modify the alpha of the managed object entity.
*/
void SetAlpha(Int32 alpha) const;
/* --------------------------------------------------------------------------------------------
* Modify the alpha of the managed object entity over the specified time.
*/
void SetAlphaEx(Int32 alpha, Int32 time) const;
/* --------------------------------------------------------------------------------------------
* Move the managed object entity to the specified position over the specified time.
*/
void MoveTo(const Vector3 & pos, Int32 time) const;
/* --------------------------------------------------------------------------------------------
* Move the managed object entity to the specified position over the specified time.
*/
void MoveToEx(Float32 x, Float32 y, Float32 z, Int32 time) const;
/* --------------------------------------------------------------------------------------------
* Move the managed object entity by the specified position over the specified time.
*/
void MoveBy(const Vector3 & pos, Int32 time) const;
/* --------------------------------------------------------------------------------------------
* Move the managed object entity by the specified position over the specified time.
*/
void MoveByEx(Float32 x, Float32 y, Float32 z, Int32 time) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the position of the managed object entity.
*/
const Vector3 & GetPosition();
/* --------------------------------------------------------------------------------------------
* Modify the position of the managed object entity.
*/
void SetPosition(const Vector3 & pos) const;
/* --------------------------------------------------------------------------------------------
* Modify the position of the managed object entity.
*/
void SetPositionEx(Float32 x, Float32 y, Float32 z) const;
/* --------------------------------------------------------------------------------------------
* Rotate the managed object entity to the specified rotation over the specified time.
*/
void RotateTo(const Quaternion & rot, Int32 time) const;
/* --------------------------------------------------------------------------------------------
* Rotate the managed object entity to the specified rotation over the specified time.
*/
void RotateToEx(Float32 x, Float32 y, Float32 z, Float32 w, Int32 time) const;
/* --------------------------------------------------------------------------------------------
* Rotate the managed object entity to the specified euler rotation over the specified time.
*/
void RotateToEuler(const Vector3 & rot, Int32 time) const;
/* --------------------------------------------------------------------------------------------
* Rotate the managed object entity to the specified euler rotation over the specified time.
*/
void RotateToEulerEx(Float32 x, Float32 y, Float32 z, Int32 time) const;
/* --------------------------------------------------------------------------------------------
* Rotate the managed object entity by the specified rotation over the specified time.
*/
void RotateBy(const Quaternion & rot, Int32 time) const;
/* --------------------------------------------------------------------------------------------
* Rotate the managed object entity by the specified rotation over the specified time.
*/
void RotateByEx(Float32 x, Float32 y, Float32 z, Float32 w, Int32 time) const;
/* --------------------------------------------------------------------------------------------
* Rotate the managed object entity by the specified euler rotation over the specified time.
*/
void RotateByEuler(const Vector3 & rot, Int32 time) const;
/* --------------------------------------------------------------------------------------------
* Rotate the managed object entity by the specified euler rotation over the specified time.
*/
void RotateByEulerEx(Float32 x, Float32 y, Float32 z, Int32 time) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the rotation of the managed object entity.
*/
const Quaternion & GetRotation();
/* --------------------------------------------------------------------------------------------
* Retrieve the euler rotation of the managed object entity.
*/
const Vector3 & GetRotationEuler();
/* --------------------------------------------------------------------------------------------
* See whether the managed object entity reports gunshots.
*/
bool GetShotReport() const;
/* --------------------------------------------------------------------------------------------
* Set whether the managed object entity reports gunshots.
*/
void SetShotReport(bool toggle) const;
/* --------------------------------------------------------------------------------------------
* See whether the managed object entity reports player bumps.
*/
bool GetBumpReport() const;
/* --------------------------------------------------------------------------------------------
* Set whether the managed object entity reports player bumps.
*/
void SetBumpReport(bool toggle) const;
// --------------------------------------------------------------------------------------------
/* --------------------------------------------------------------------------------------------
* Retrieve the position on the x axis of the managed object entity.
*/
Float32 GetPosX() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the position on the y axis of the managed object entity.
*/
Float32 GetPosY() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the position on the z axis of the managed object entity.
*/
Float32 GetPosZ() const;
/* --------------------------------------------------------------------------------------------
* Modify the position on the x axis of the managed object entity.
*/
void SetPosX(Float32 x) const;
/* --------------------------------------------------------------------------------------------
* Modify the position on the y axis of the managed object entity.
*/
void SetPosY(Float32 y) const;
/* --------------------------------------------------------------------------------------------
* Modify the position on the z axis of the managed object entity.
*/
void SetPosZ(Float32 z) const;
// --------------------------------------------------------------------------------------------
/* --------------------------------------------------------------------------------------------
* Retrieve the rotation on the x axis of the managed object entity.
*/
Float32 GetRotX() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the rotation on the y axis of the managed object entity.
*/
Float32 GetRotY() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the rotation on the z axis of the managed object entity.
*/
Float32 GetRotZ() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the rotation amount of the managed object entity.
*/
Float32 GetRotW() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the euler rotation on the x axis of the managed object entity.
*/
Float32 GetERotX() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the euler rotation on the y axis of the managed object entity.
*/
Float32 GetERotY() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the euler rotation on the z axis of the managed object entity.
*/
Float32 GetERotZ() const;
};

View File

@ -11,15 +11,20 @@ namespace SqMod {
Vector3 CPickup::s_Vector3;
// ------------------------------------------------------------------------------------------------
SQChar CPickup::s_StrID[SQMOD_PICKUP_POOL][8];
const Int32 CPickup::Max = SQMOD_PICKUP_POOL;
// ------------------------------------------------------------------------------------------------
const Int32 CPickup::Max = SQMOD_PICKUP_POOL;
SQInteger CPickup::Typename(HSQUIRRELVM vm)
{
static SQChar name[] = _SC("SqPickup");
sq_pushstring(vm, name, sizeof(name));
return 1;
}
// ------------------------------------------------------------------------------------------------
CPickup::CPickup(Int32 id)
: m_ID(VALID_ENTITYGETEX(id, SQMOD_PICKUP_POOL))
, m_Tag(VALID_ENTITY(m_ID) ? s_StrID[m_ID] : _SC("-1"))
, m_Tag(ToStrF("%d", id))
{
/* ... */
}
@ -41,221 +46,289 @@ Int32 CPickup::Cmp(const CPickup & o) const
return -1;
}
CSStr CPickup::ToString() const
// ------------------------------------------------------------------------------------------------
const String & CPickup::ToString() const
{
return VALID_ENTITYEX(m_ID, SQMOD_PICKUP_POOL) ? s_StrID[m_ID] : _SC("-1");
return m_Tag;
}
// ------------------------------------------------------------------------------------------------
CSStr CPickup::GetTag() const
const String & CPickup::GetTag() const
{
return m_Tag.c_str();
return m_Tag;
}
// ------------------------------------------------------------------------------------------------
void CPickup::SetTag(CSStr tag)
{
m_Tag.assign(tag);
}
// ------------------------------------------------------------------------------------------------
Object & CPickup::GetData()
{
if (Validate())
return m_Data;
return NullObject();
// Validate the managed identifier
Validate();
// Return the requested information
return m_Data;
}
// ------------------------------------------------------------------------------------------------
void CPickup::SetData(Object & data)
{
if (Validate())
m_Data = data;
// Validate the managed identifier
Validate();
// Apply the specified value
m_Data = data;
}
// ------------------------------------------------------------------------------------------------
bool CPickup::Destroy(Int32 header, Object & payload)
{
// Validate the managed identifier
Validate();
// Perform the requested operation
return _Core->DelPickup(m_ID, header, payload);
}
// ------------------------------------------------------------------------------------------------
bool CPickup::BindEvent(Int32 evid, Object & env, Function & func) const
void CPickup::BindEvent(Int32 evid, Object & env, Function & func) const
{
if (!Validate())
return false;
// Validate the managed identifier
Validate();
// Obtain the function instance called for this event
Function & event = _Core->GetPickupEvent(m_ID, evid);
// Is the specified callback function null?
if (func.IsNull())
event.Release();
event.Release(); // Then release the current callback
// Assign the specified environment and function
else
event = Function(env.GetVM(), env, func.GetFunc());
return true;
}
// ------------------------------------------------------------------------------------------------
bool CPickup::IsStreamedFor(CPlayer & player) const
{
// Is the specified player even valid?
if (!player.IsActive())
SqThrow("Invalid player argument: null");
else if (Validate())
return _Func->IsPickupStreamedForPlayer(m_ID, player.GetID());
return false;
SqThrowF("Invalid player argument: null");
// Validate the managed identifier
Validate();
// Return the requested information
return _Func->IsPickupStreamedForPlayer(m_ID, player.GetID());
}
// ------------------------------------------------------------------------------------------------
Int32 CPickup::GetModel() const
{
if (Validate())
return _Func->PickupGetModel(m_ID);
return -1;
// Validate the managed identifier
Validate();
// Return the requested information
return _Func->PickupGetModel(m_ID);
}
// ------------------------------------------------------------------------------------------------
Int32 CPickup::GetWorld() const
{
if (Validate())
return _Func->GetPickupWorld(m_ID);
return -1;
// Validate the managed identifier
Validate();
// Return the requested information
return _Func->GetPickupWorld(m_ID);
}
// ------------------------------------------------------------------------------------------------
void CPickup::SetWorld(Int32 world) const
{
if (Validate())
_Func->SetPickupWorld(m_ID, world);
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->SetPickupWorld(m_ID, world);
}
// ------------------------------------------------------------------------------------------------
Int32 CPickup::GetAlpha() const
{
if (Validate())
return _Func->GetVehicleModel(m_ID);
return -1;
// Validate the managed identifier
Validate();
// Return the requested information
return _Func->GetVehicleModel(m_ID);
}
// ------------------------------------------------------------------------------------------------
void CPickup::SetAlpha(Int32 alpha) const
{
if (Validate())
_Func->PickupSetAlpha(m_ID, alpha);
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->PickupSetAlpha(m_ID, alpha);
}
// ------------------------------------------------------------------------------------------------
bool CPickup::GetAutomatic() const
{
if (Validate())
return _Func->PickupIsAutomatic(m_ID);
return false;
// Validate the managed identifier
Validate();
// Return the requested information
return _Func->PickupIsAutomatic(m_ID);
}
// ------------------------------------------------------------------------------------------------
void CPickup::SetAutomatic(bool toggle) const
{
if (Validate())
_Func->PickupSetAutomatic(m_ID, toggle);
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->PickupSetAutomatic(m_ID, toggle);
}
// ------------------------------------------------------------------------------------------------
Int32 CPickup::GetAutoTimer() const
{
if (Validate())
return _Func->GetPickupAutoTimer(m_ID);
return -1;
// Validate the managed identifier
Validate();
// Return the requested information
return _Func->GetPickupAutoTimer(m_ID);
}
// ------------------------------------------------------------------------------------------------
void CPickup::SetAutoTimer(Int32 timer) const
{
if (Validate())
_Func->SetPickupAutoTimer(m_ID, timer);
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->SetPickupAutoTimer(m_ID, timer);
}
// ------------------------------------------------------------------------------------------------
void CPickup::Refresh() const
{
if (Validate())
_Func->PickupRefresh(m_ID);
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->PickupRefresh(m_ID);
}
// ------------------------------------------------------------------------------------------------
const Vector3 & CPickup::GetPosition()
{
// Validate the managed identifier
Validate();
// Clear previous position information, if any
s_Vector3.Clear();
if (Validate())
_Func->PickupGetPos(m_ID, &s_Vector3.x, &s_Vector3.y, &s_Vector3.z);
// Query the server for the position values
_Func->PickupGetPos(m_ID, &s_Vector3.x, &s_Vector3.y, &s_Vector3.z);
// Return the requested information
return s_Vector3;
}
// ------------------------------------------------------------------------------------------------
void CPickup::SetPosition(const Vector3 & pos) const
{
if (Validate())
_Func->PickupSetPos(m_ID, pos.x, pos.y, pos.z);
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->PickupSetPos(m_ID, pos.x, pos.y, pos.z);
}
// ------------------------------------------------------------------------------------------------
void CPickup::SetPositionEx(Float32 x, Float32 y, Float32 z) const
{
if (Validate())
_Func->PickupSetPos(m_ID, x, y, z);
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->PickupSetPos(m_ID, x, y, z);
}
// ------------------------------------------------------------------------------------------------
Int32 CPickup::GetQuantity() const
{
if (Validate())
return _Func->PickupGetQuantity(m_ID);
return -1;
// Validate the managed identifier
Validate();
// Return the requested information
return _Func->PickupGetQuantity(m_ID);
}
// ------------------------------------------------------------------------------------------------
Float32 CPickup::GetPosX() const
{
// Validate the managed identifier
Validate();
// Clear previous position information, if any
s_Vector3.x = 0;
if (Validate())
_Func->PickupGetPos(m_ID, &s_Vector3.x, NULL, NULL);
// Query the server for the requested component value
_Func->PickupGetPos(m_ID, &s_Vector3.x, NULL, NULL);
// Return the requested information
return s_Vector3.x;
}
// ------------------------------------------------------------------------------------------------
Float32 CPickup::GetPosY() const
{
// Validate the managed identifier
Validate();
// Clear previous position information, if any
s_Vector3.y = 0;
if (Validate())
_Func->PickupGetPos(m_ID, NULL, &s_Vector3.y, NULL);
// Query the server for the requested component value
_Func->PickupGetPos(m_ID, NULL, &s_Vector3.y, NULL);
// Return the requested information
return s_Vector3.y;
}
// ------------------------------------------------------------------------------------------------
Float32 CPickup::GetPosZ() const
{
// Validate the managed identifier
Validate();
// Clear previous position information, if any
s_Vector3.z = 0;
if (Validate())
_Func->PickupGetPos(m_ID, NULL, NULL, &s_Vector3.z);
// Query the server for the requested component value
_Func->PickupGetPos(m_ID, NULL, NULL, &s_Vector3.z);
// Return the requested information
return s_Vector3.z;
}
// ------------------------------------------------------------------------------------------------
void CPickup::SetPosX(Float32 x) const
{
if (Validate())
{
_Func->PickupGetPos(m_ID, NULL, &s_Vector3.y, &s_Vector3.z);
_Func->PickupSetPos(m_ID, x, s_Vector3.y, s_Vector3.z);
}
}
void CPickup::SetPosY(Float32 y) const
{
if (Validate())
{
_Func->PickupGetPos(m_ID, &s_Vector3.x, NULL, &s_Vector3.z);
_Func->PickupSetPos(m_ID, s_Vector3.x, y, s_Vector3.z);
}
}
void CPickup::SetPosZ(Float32 z) const
{
if (Validate())
{
_Func->PickupGetPos(m_ID, &s_Vector3.x, &s_Vector3.y, NULL);
_Func->PickupSetPos(m_ID, s_Vector3.z, s_Vector3.y, z);
}
// Validate the managed identifier
Validate();
// Retrieve the current values for unchanged components
_Func->PickupGetPos(m_ID, NULL, &s_Vector3.y, &s_Vector3.z);
// Perform the requested operation
_Func->PickupSetPos(m_ID, x, s_Vector3.y, s_Vector3.z);
}
// ------------------------------------------------------------------------------------------------
static Object & CreatePickupEx(Int32 model, Int32 world, Int32 quantity,
void CPickup::SetPosY(Float32 y) const
{
// Validate the managed identifier
Validate();
// Retrieve the current values for unchanged components
_Func->PickupGetPos(m_ID, &s_Vector3.x, NULL, &s_Vector3.z);
// Perform the requested operation
_Func->PickupSetPos(m_ID, s_Vector3.x, y, s_Vector3.z);
}
// ------------------------------------------------------------------------------------------------
void CPickup::SetPosZ(Float32 z) const
{
// Validate the managed identifier
Validate();
// Retrieve the current values for unchanged components
_Func->PickupGetPos(m_ID, &s_Vector3.x, &s_Vector3.y, NULL);
// Perform the requested operation
_Func->PickupSetPos(m_ID, s_Vector3.z, s_Vector3.y, z);
}
// ------------------------------------------------------------------------------------------------
static Object & Pickup_CreateEx(Int32 model, Int32 world, Int32 quantity,
Float32 x, Float32 y, Float32 z, Int32 alpha, bool automatic)
{
return _Core->NewPickup(model, world, quantity, x, y, z, alpha, automatic,
SQMOD_CREATE_DEFAULT, NullObject());
}
static Object & CreatePickupEx(Int32 model, Int32 world, Int32 quantity,
static Object & Pickup_CreateEx(Int32 model, Int32 world, Int32 quantity,
Float32 x, Float32 y, Float32 z, Int32 alpha, bool automatic,
Int32 header, Object & payload)
{
@ -263,14 +336,14 @@ static Object & CreatePickupEx(Int32 model, Int32 world, Int32 quantity,
}
// ------------------------------------------------------------------------------------------------
static Object & CreatePickup(Int32 model, Int32 world, Int32 quantity, const Vector3 & pos,
static Object & Pickup_Create(Int32 model, Int32 world, Int32 quantity, const Vector3 & pos,
Int32 alpha, bool automatic)
{
return _Core->NewPickup(model, world, quantity, pos.x, pos.y, pos.z, alpha, automatic,
SQMOD_CREATE_DEFAULT, NullObject());
}
static Object & CreatePickup(Int32 model, Int32 world, Int32 quantity, const Vector3 & pos,
static Object & Pickup_Create(Int32 model, Int32 world, Int32 quantity, const Vector3 & pos,
Int32 alpha, bool automatic, Int32 header, Object & payload)
{
return _Core->NewPickup(model, world, quantity, pos.x, pos.y, pos.z, alpha, automatic,
@ -282,22 +355,24 @@ void Register_CPickup(HSQUIRRELVM vm)
{
RootTable(vm).Bind(_SC("SqPickup"),
Class< CPickup, NoConstructor< CPickup > >(vm, _SC("SqPickup"))
/* Metamethods */
// Metamethods
.Func(_SC("_cmp"), &CPickup::Cmp)
.SquirrelFunc(_SC("_typename"), &CPickup::Typename)
.Func(_SC("_tostring"), &CPickup::ToString)
/* Core Properties */
// Static values
.SetStaticValue(_SC("MaxID"), CPickup::Max)
// Core Properties
.Prop(_SC("ID"), &CPickup::GetID)
.Prop(_SC("Tag"), &CPickup::GetTag, &CPickup::SetTag)
.Prop(_SC("Data"), &CPickup::GetData, &CPickup::SetData)
.Prop(_SC("MaxID"), &CPickup::GetMaxID)
.Prop(_SC("Active"), &CPickup::IsActive)
/* Core Functions */
// Core Functions
.Func(_SC("Bind"), &CPickup::BindEvent)
/* Core Overloads */
// Core Overloads
.Overload< bool (CPickup::*)(void) >(_SC("Destroy"), &CPickup::Destroy)
.Overload< bool (CPickup::*)(Int32) >(_SC("Destroy"), &CPickup::Destroy)
.Overload< bool (CPickup::*)(Int32, Object &) >(_SC("Destroy"), &CPickup::Destroy)
/* Properties */
// Properties
.Prop(_SC("Model"), &CPickup::GetModel)
.Prop(_SC("World"), &CPickup::GetWorld, &CPickup::SetWorld)
.Prop(_SC("Alpha"), &CPickup::GetAlpha, &CPickup::SetAlpha)
@ -311,22 +386,21 @@ void Register_CPickup(HSQUIRRELVM vm)
.Prop(_SC("X"), &CPickup::GetPosX, &CPickup::SetPosX)
.Prop(_SC("Y"), &CPickup::GetPosY, &CPickup::SetPosY)
.Prop(_SC("Z"), &CPickup::GetPosZ, &CPickup::SetPosZ)
/* Functions */
// Functions
.Func(_SC("StreamedFor"), &CPickup::IsStreamedFor)
.Func(_SC("Refresh"), &CPickup::Refresh)
.Func(_SC("SetPos"), &CPickup::SetPositionEx)
.Func(_SC("SetPosition"), &CPickup::SetPositionEx)
// Static Overloads
.StaticOverload< Object & (*)(Int32, Int32, Int32, Float32, Float32, Float32, Int32, bool) >
(_SC("CreateEx"), &Pickup_CreateEx)
.StaticOverload< Object & (*)(Int32, Int32, Int32, Float32, Float32, Float32, Int32, bool, Int32, Object &) >
(_SC("CreateEx"), &Pickup_CreateEx)
.StaticOverload< Object & (*)(Int32, Int32, Int32, const Vector3 &, Int32, bool) >
(_SC("Create"), &Pickup_Create)
.StaticOverload< Object & (*)(Int32, Int32, Int32, const Vector3 &, Int32, bool, Int32, Object &) >
(_SC("Create"), &Pickup_Create)
);
RootTable(vm)
.Overload< Object & (*)(Int32, Int32, Int32, Float32, Float32, Float32, Int32, bool) >
(_SC("CreatePickupEx"), &CreatePickupEx)
.Overload< Object & (*)(Int32, Int32, Int32, Float32, Float32, Float32, Int32, bool, Int32, Object &) >
(_SC("CreatePickupEx"), &CreatePickupEx)
.Overload< Object & (*)(Int32, Int32, Int32, const Vector3 &, Int32, bool) >
(_SC("CreatePickup"), &CreatePickup)
.Overload< Object & (*)(Int32, Int32, Int32, const Vector3 &, Int32, bool, Int32, Object &) >
(_SC("CreatePickup"), &CreatePickup);
}
} // Namespace:: SqMod

View File

@ -8,7 +8,7 @@
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Manages Pickup instances.
* Manages a single pickup entity.
*/
class CPickup
{
@ -20,20 +20,19 @@ private:
// --------------------------------------------------------------------------------------------
static Vector3 s_Vector3;
/* --------------------------------------------------------------------------------------------
* Cached identifiers for fast integer to string conversion.
*/
static SQChar s_StrID[SQMOD_PICKUP_POOL][8];
/* --------------------------------------------------------------------------------------------
* Identifier of the managed entity.
*/
Int32 m_ID;
/* --------------------------------------------------------------------------------------------
* User tag and data associated with this instance.
* User tag associated with this instance.
*/
String m_Tag;
/* --------------------------------------------------------------------------------------------
* User data associated with this instance.
*/
Object m_Data;
/* --------------------------------------------------------------------------------------------
@ -41,20 +40,22 @@ private:
*/
CPickup(Int32 id);
public:
/* --------------------------------------------------------------------------------------------
* Maximum possible number that could represent an identifier for this entity type.
*/
static const Int32 Max;
/* --------------------------------------------------------------------------------------------
* Copy constructor. (disabled)
*/
CPickup(const CPickup &);
CPickup(const CPickup &) = delete;
/* --------------------------------------------------------------------------------------------
* Copy assignment operator. (disabled)
* Move constructor. (disabled)
*/
CPickup & operator = (const CPickup &);
public:
// --------------------------------------------------------------------------------------------
static const Int32 Max;
CPickup(CPickup &&) = delete;
/* --------------------------------------------------------------------------------------------
* Destructor.
@ -62,14 +63,22 @@ public:
~CPickup();
/* --------------------------------------------------------------------------------------------
* See whether this instance manages a valid entity.
* Copy assignment operator. (disabled)
*/
bool Validate() const
CPickup & operator = (const CPickup &) = delete;
/* --------------------------------------------------------------------------------------------
* Move assignment operator. (disabled)
*/
CPickup & operator = (CPickup &&) = delete;
/* --------------------------------------------------------------------------------------------
* See whether this instance manages a valid entity instance otherwise throw an exception.
*/
void Validate() const
{
if (VALID_ENTITY(m_ID))
return true;
SqThrow("Invalid pickup reference [%s]", m_Tag.c_str());
return false;
if (INVALID_ENTITY(m_ID))
SqThrowF("Invalid pickup reference [%s]", m_Tag.c_str());
}
/* --------------------------------------------------------------------------------------------
@ -80,27 +89,33 @@ public:
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
CSStr ToString() const;
const String & ToString() const;
/* --------------------------------------------------------------------------------------------
* Used by the script engine to retrieve the name from instances of this type.
*/
static SQInteger Typename(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Retrieve the identifier of the entity managed by this instance.
*/
Int32 GetID() const { return m_ID; }
/* --------------------------------------------------------------------------------------------
* Retrieve the maximum possible identifier to an entity of this type.
*/
Int32 GetMaxID() const { return SQMOD_PICKUP_POOL; }
Int32 GetID() const
{
return m_ID;
}
/* --------------------------------------------------------------------------------------------
* Check whether this instance manages a valid entity.
*/
bool IsActive() const { return VALID_ENTITY(m_ID); }
bool IsActive() const
{
return VALID_ENTITY(m_ID);
}
/* --------------------------------------------------------------------------------------------
* Retrieve the associated user tag.
*/
CSStr GetTag() const;
const String & GetTag() const;
/* --------------------------------------------------------------------------------------------
* Modify the associated user tag.
@ -117,37 +132,135 @@ public:
*/
void SetData(Object & data);
// --------------------------------------------------------------------------------------------
/* --------------------------------------------------------------------------------------------
* Destroy the managed pickup entity.
*/
bool Destroy()
{
return Destroy(0, NullObject());
}
/* --------------------------------------------------------------------------------------------
* Destroy the managed pickup entity.
*/
bool Destroy(Int32 header)
{
return Destroy(header, NullObject());
}
/* --------------------------------------------------------------------------------------------
* Destroy the managed pickup entity.
*/
bool Destroy(Int32 header, Object & payload);
bool Destroy() { return Destroy(0, NullObject()); }
bool Destroy(Int32 header) { return Destroy(header, NullObject()); }
// --------------------------------------------------------------------------------------------
bool BindEvent(Int32 evid, Object & env, Function & func) const;
/* --------------------------------------------------------------------------------------------
* Bind to an event supported by this entity type.
*/
void BindEvent(Int32 evid, Object & env, Function & func) const;
// --------------------------------------------------------------------------------------------
/* --------------------------------------------------------------------------------------------
* See if the managed pickup entity is streamed for the specified player.
*/
bool IsStreamedFor(CPlayer & player) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the model of the managed pickup entity.
*/
Int32 GetModel() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the world in which the managed pickup entity exists.
*/
Int32 GetWorld() const;
/* --------------------------------------------------------------------------------------------
* Mpdify the world in which the managed pickup entity exists.
*/
void SetWorld(Int32 world) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the alpha of the managed pickup entity.
*/
Int32 GetAlpha() const;
/* --------------------------------------------------------------------------------------------
* Mpdify the alpha of the managed pickup entity.
*/
void SetAlpha(Int32 alpha) const;
/* --------------------------------------------------------------------------------------------
* See whether the managed pickup entity is automatic.
*/
bool GetAutomatic() const;
/* --------------------------------------------------------------------------------------------
* Set whether the managed pickup entity is automatic.
*/
void SetAutomatic(bool toggle) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the automatic timer of the managed pickup entity.
*/
Int32 GetAutoTimer() const;
/* --------------------------------------------------------------------------------------------
* Mpdify the automatic timer of the managed pickup entity.
*/
void SetAutoTimer(Int32 timer) const;
/* --------------------------------------------------------------------------------------------
* Refresh the managed pickup entity.
*/
void Refresh() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the position of the managed pickup entity.
*/
const Vector3 & GetPosition();
/* --------------------------------------------------------------------------------------------
* Mpdify the position of the managed pickup entity.
*/
void SetPosition(const Vector3 & pos) const;
/* --------------------------------------------------------------------------------------------
* Mpdify the position of the managed pickup entity.
*/
void SetPositionEx(Float32 x, Float32 y, Float32 z) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the quantity of the managed pickup entity.
*/
Int32 GetQuantity() const;
// --------------------------------------------------------------------------------------------
/* --------------------------------------------------------------------------------------------
* Retrieve the position on the x axis of the managed pickup entity.
*/
Float32 GetPosX() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the position on the y axis of the managed pickup entity.
*/
Float32 GetPosY() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the position on the z axis of the managed pickup entity.
*/
Float32 GetPosZ() const;
/* --------------------------------------------------------------------------------------------
* Modify the position on the x axis of the managed pickup entity.
*/
void SetPosX(Float32 x) const;
/* --------------------------------------------------------------------------------------------
* Modify the position on the y axis of the managed pickup entity.
*/
void SetPosY(Float32 y) const;
/* --------------------------------------------------------------------------------------------
* Modify the position on the z axis of the managed pickup entity.
*/
void SetPosZ(Float32 z) const;
};

File diff suppressed because it is too large Load Diff

View File

@ -8,7 +8,7 @@
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Manages Player instances.
* Manages a single player entity.
*/
class CPlayer
{
@ -24,20 +24,19 @@ private:
// --------------------------------------------------------------------------------------------
static SQChar s_Buffer[SQMOD_PLAYER_TMP_BUFFER];
/* --------------------------------------------------------------------------------------------
* Cached identifiers for fast integer to string conversion.
*/
static SQChar s_StrID[SQMOD_PLAYER_POOL][8];
/* --------------------------------------------------------------------------------------------
* Identifier of the managed entity.
*/
Int32 m_ID;
/* --------------------------------------------------------------------------------------------
* User tag and data associated with this instance.
* User tag associated with this instance.
*/
String m_Tag;
/* --------------------------------------------------------------------------------------------
* User data associated with this instance.
*/
Object m_Data;
/* --------------------------------------------------------------------------------------------
@ -45,35 +44,45 @@ private:
*/
CPlayer(Int32 id);
public:
/* --------------------------------------------------------------------------------------------
* Maximum possible number that could represent an identifier for this entity type.
*/
static const Int32 Max;
/* --------------------------------------------------------------------------------------------
* Copy constructor. (disabled)
*/
CPlayer(const CPlayer &);
CPlayer(const CPlayer &) = delete;
/* --------------------------------------------------------------------------------------------
* Copy assignment operator. (disabled)
* Move constructor. (disabled)
*/
CPlayer & operator = (const CPlayer &);
public:
// --------------------------------------------------------------------------------------------
static const Int32 Max;
CPlayer(CPlayer &&) = delete;
/* --------------------------------------------------------------------------------------------
* Destructor.
*/
~CPlayer();
/* --------------------------------------------------------------------------------------------
* Copy assignment operator. (disabled)
*/
CPlayer & operator = (const CPlayer &) = delete;
/* --------------------------------------------------------------------------------------------
* Move assignment operator. (disabled)
*/
CPlayer & operator = (CPlayer &&) = delete;
/* --------------------------------------------------------------------------------------------
* See whether this instance manages a valid entity.
*/
bool Validate() const
void Validate() const
{
if (VALID_ENTITY(m_ID))
return true;
SqThrow("Invalid player reference [%s]", m_Tag.c_str());
return false;
if (INVALID_ENTITY(m_ID))
SqThrowF("Invalid player reference [%s]", m_Tag.c_str());
}
/* --------------------------------------------------------------------------------------------
@ -84,27 +93,33 @@ public:
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
CSStr ToString() const;
const String & ToString() const;
/* --------------------------------------------------------------------------------------------
* Used by the script engine to retrieve the name from instances of this type.
*/
static SQInteger Typename(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Retrieve the identifier of the entity managed by this instance.
*/
Int32 GetID() const { return m_ID; }
/* --------------------------------------------------------------------------------------------
* Retrieve the maximum possible identifier to an entity of this type.
*/
Int32 GetMaxID() const { return SQMOD_PLAYER_POOL; }
Int32 GetID() const
{
return m_ID;
}
/* --------------------------------------------------------------------------------------------
* Check whether this instance manages a valid entity.
*/
bool IsActive() const { return VALID_ENTITY(m_ID); }
bool IsActive() const
{
return VALID_ENTITY(m_ID);
}
/* --------------------------------------------------------------------------------------------
* Retrieve the associated user tag.
*/
CSStr GetTag() const;
const String & GetTag() const;
/* --------------------------------------------------------------------------------------------
* Modify the associated user tag.
@ -121,141 +136,639 @@ public:
*/
void SetData(Object & data);
// --------------------------------------------------------------------------------------------
bool BindEvent(Int32 evid, Object & env, Function & func) const;
/* --------------------------------------------------------------------------------------------
* Bind to an event supported by this entity type.
*/
void BindEvent(Int32 evid, Object & env, Function & func) const;
// --------------------------------------------------------------------------------------------
/* --------------------------------------------------------------------------------------------
* See if the managed player entity is streamed for the specified player.
*/
bool IsStreamedFor(CPlayer & player) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the class of the managed player entity.
*/
Int32 GetClass() const;
/* --------------------------------------------------------------------------------------------
* See whether the managed player entity has administrator privileges.
*/
bool GetAdmin() const;
/* --------------------------------------------------------------------------------------------
* Set whether the managed player entity has administrator privileges.
*/
void SetAdmin(bool toggle) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the ip address of the managed player entity.
*/
CSStr GetIP() const;
/* --------------------------------------------------------------------------------------------
* Kick the managed player entity from the server.
*/
void Kick() const;
/* --------------------------------------------------------------------------------------------
* Ban the managed player entity from the server.
*/
void Ban() const;
/* --------------------------------------------------------------------------------------------
* See whether the managed player entity is connected.
*/
bool IsConnected() const;
/* --------------------------------------------------------------------------------------------
* See whether the managed player entity is spawned.
*/
bool IsSpawned() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the key of the managed player entity.
*/
Uint32 GetKey() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the world in which the managed player entity exists.
*/
Int32 GetWorld() const;
/* --------------------------------------------------------------------------------------------
* Modify the world in which the managed player entity exists.
*/
void SetWorld(Int32 world) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the secondary world of the managed player entity.
*/
Int32 GetSecWorld() const;
/* --------------------------------------------------------------------------------------------
* Modify the secondary world of the managed player entity.
*/
void SetSecWorld(Int32 world) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the unique world of the managed player entity.
*/
Int32 GetUniqueWorld() const;
/* --------------------------------------------------------------------------------------------
* See whether the managed player entity is compatible with the specified world.
*/
bool IsWorldCompatible(Int32 world) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the nick name of the managed player entity.
*/
CSStr GetName() const;
/* --------------------------------------------------------------------------------------------
* Modify the nick name of the managed player entity.
*/
void SetName(CSStr name) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the team of the managed player entity.
*/
Int32 GetTeam() const;
/* --------------------------------------------------------------------------------------------
* Modify the team of the managed player entity.
*/
void SetTeam(Int32 team) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the skin identifier of the managed player entity.
*/
Int32 GetSkin() const;
/* --------------------------------------------------------------------------------------------
* Modify the skin identifier of the managed player entity.
*/
void SetSkin(Int32 skin) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the color of the managed player entity.
*/
const Color3 & GetColor() const;
/* --------------------------------------------------------------------------------------------
* Modify the color of the managed player entity.
*/
void SetColor(const Color3 & color) const;
/* --------------------------------------------------------------------------------------------
* Modify the color of the managed player entity.
*/
void SetColorEx(Uint8 r, Uint8 g, Uint8 b) const;
/* --------------------------------------------------------------------------------------------
* Force the managed player entity to spawn in the game.
*/
void ForceSpawn() const;
/* --------------------------------------------------------------------------------------------
* Force the managed player entity to select a class.
*/
void ForceSelect() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the money amount of the managed player entity.
*/
Int32 GetMoney() const;
/* --------------------------------------------------------------------------------------------
* Modify the money amount of the managed player entity.
*/
void SetMoney(Int32 amount) const;
/* --------------------------------------------------------------------------------------------
* Give a certain amount of money to the managed player entity.
*/
void GiveMoney(Int32 amount) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the score of the managed player entity.
*/
Int32 GetScore() const;
/* --------------------------------------------------------------------------------------------
* Modify the score of the managed player entity.
*/
void SetScore(Int32 score) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the connection latency of the managed player entity.
*/
Int32 GetPing() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the frames per second of the managed player entity.
*/
Float32 GetFPS() const;
/* --------------------------------------------------------------------------------------------
* See whether the managed player entity is typing.
*/
bool IsTyping() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the unique user identifier of the managed player entity.
*/
CSStr GetUID() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the unique user identifier version 2 of the managed player entity.
*/
CSStr GetUID2() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the current health of the managed player entity.
*/
Float32 GetHealth() const;
/* --------------------------------------------------------------------------------------------
* Modify the health of the managed player entity.
*/
void SetHealth(Float32 amount) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the current health of the managed player entity.
*/
Float32 GetArmor() const;
/* --------------------------------------------------------------------------------------------
* Modify the health of the managed player entity.
*/
void SetArmor(Float32 amount) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the immunity flags of the managed player entity.
*/
Int32 GetImmunity() const;
/* --------------------------------------------------------------------------------------------
* Modify the immunity flags of the managed player entity.
*/
void SetImmunity(Int32 flags) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the position of the managed player entity.
*/
const Vector3 & GetPosition() const;
/* --------------------------------------------------------------------------------------------
* Modify the position of the managed player entity.
*/
void SetPosition(const Vector3 & pos) const;
/* --------------------------------------------------------------------------------------------
* Modify the position of the managed player entity.
*/
void SetPositionEx(Float32 x, Float32 y, Float32 z) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the speed of the managed player entity.
*/
const Vector3 & GetSpeed() const;
/* --------------------------------------------------------------------------------------------
* Modify the speed of the managed player entity.
*/
void SetSpeed(const Vector3 & vel) const;
/* --------------------------------------------------------------------------------------------
* Modify the speed of the managed player entity.
*/
void SetSpeedEx(Float32 x, Float32 y, Float32 z) const;
/* --------------------------------------------------------------------------------------------
* Modify the speed of the managed player entity.
*/
void AddSpeed(const Vector3 & vel) const;
/* --------------------------------------------------------------------------------------------
* Modify the speed of the managed player entity.
*/
void AddSpeedEx(Float32 x, Float32 y, Float32 z) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the heading angle of the managed player entity.
*/
Float32 GetHeading() const;
/* --------------------------------------------------------------------------------------------
* Modify the heading angle of the managed player entity.
*/
void SetHeading(Float32 angle) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the alpha of the managed player entity.
*/
Int32 GetAlpha() const;
/* --------------------------------------------------------------------------------------------
* Modify the alpha of the managed player entity.
*/
void SetAlpha(Int32 alpha, Int32 fade) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the vehicle status of the managed player entity.
*/
Int32 GetVehicleStatus() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the occupied vehicle slot by the managed player entity.
*/
Int32 GetOccupiedSlot() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the vehicle in which the managed player entity is embarked.
*/
Object & GetVehicle() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the vehicle identifier in which the managed player entity is embarked.
*/
Int32 GetVehicleID() const;
/* --------------------------------------------------------------------------------------------
* See whether the managed player entity can be controlled.
*/
bool GetControllable() const;
/* --------------------------------------------------------------------------------------------
* Set whether the managed player entity can be controlled.
*/
void SetControllable(bool toggle) const;
/* --------------------------------------------------------------------------------------------
* See whether the managed player entity can driveby.
*/
bool GetDriveby() const;
/* --------------------------------------------------------------------------------------------
* Set whether the managed player entity can driveby.
*/
void SetDriveby(bool toggle) const;
/* --------------------------------------------------------------------------------------------
* See whether the managed player entity has white scanlines.
*/
bool GetWhiteScanlines() const;
/* --------------------------------------------------------------------------------------------
* Set whether the managed player entity has white scanlines.
*/
void SetWhiteScanlines(bool toggle) const;
/* --------------------------------------------------------------------------------------------
* See whether the managed player entity has green scanlines.
*/
bool GetGreenScanlines() const;
/* --------------------------------------------------------------------------------------------
* Set whether the managed player entity has green scanlines.
*/
void SetGreenScanlines(bool toggle) const;
/* --------------------------------------------------------------------------------------------
* See whether the managed player entity has widescreen.
*/
bool GetWidescreen() const;
/* --------------------------------------------------------------------------------------------
* Set whether the managed player entity has widescreen.
*/
void SetWidescreen(bool toggle) const;
/* --------------------------------------------------------------------------------------------
* See whether the managed player entity displays markers.
*/
bool GetShowMarkers() const;
/* --------------------------------------------------------------------------------------------
* Set whether the managed player entity displays markers.
*/
void SetShowMarkers(bool toggle) const;
/* --------------------------------------------------------------------------------------------
* See whether the managed player entity has attacking privileges.
*/
bool GetAttackPriv() const;
/* --------------------------------------------------------------------------------------------
* Set whether the managed player entity has attacking privileges.
*/
void SetAttackPriv(bool toggle) const;
/* --------------------------------------------------------------------------------------------
* See whether the managed player entity has markers.
*/
bool GetHasMarker() const;
/* --------------------------------------------------------------------------------------------
* Set whether the managed player entity has markers.
*/
void SetHasMarker(bool toggle) const;
/* --------------------------------------------------------------------------------------------
* See whether the managed player entity has chat tags.
*/
bool GetChatTags() const;
/* --------------------------------------------------------------------------------------------
* Set whether the managed player entity has chat tags.
*/
void SetChatTags(bool toggle) const;
/* --------------------------------------------------------------------------------------------
* See whether the managed player entity is under drunk effects.
*/
bool GetDrunkEffects() const;
/* --------------------------------------------------------------------------------------------
* Set whether the managed player entity is under drunk effects.
*/
void SetDrunkEffects(bool toggle) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the weapon identifier of the managed player entity.
*/
Int32 GetWeapon() const;
/* --------------------------------------------------------------------------------------------
* Modify the weapon of the managed player entity.
*/
void SetWeapon(Int32 wep, Int32 ammo) const;
/* --------------------------------------------------------------------------------------------
* Give a weapon of the managed player entity.
*/
void GiveWeapon(Int32 wep, Int32 ammo) const;
/* --------------------------------------------------------------------------------------------
* Strip the managed player entity of all weapons.
*/
void StripWeapons() const;
/* --------------------------------------------------------------------------------------------
* Modify the camera position of the managed player entity.
*/
void SetCameraPosition(const Vector3 & pos, const Vector3 & aim) const;
/* --------------------------------------------------------------------------------------------
* Modify the camera position of the managed player entity.
*/
void SetCameraPosition(Float32 xp, Float32 yp, Float32 zp, Float32 xa, Float32 ya, Float32 za) const;
/* --------------------------------------------------------------------------------------------
* Restore the camera position of the managed player entity.
*/
void RestoreCamera() const;
/* --------------------------------------------------------------------------------------------
* See whether the managed player entity has camera locked.
*/
bool IsCameraLocked() const;
/* --------------------------------------------------------------------------------------------
* Modify the animation of the managed player entity.
*/
void SetAnimation(Int32 group, Int32 anim) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the wanted level of the managed player entity.
*/
Int32 GetWantedLevel() const;
/* --------------------------------------------------------------------------------------------
* Modify the wanted level of the managed player entity.
*/
void SetWantedLevel(Int32 level) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the vehicle that the managed player entity is standing on.
*/
Object & StandingOnVehicle() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the object that the managed player entity is standing on.
*/
Object & StandingOnObject() const;
/* --------------------------------------------------------------------------------------------
* See whether the managed player entity is away.
*/
bool IsAway() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the player that the managed player entity is spectating.
*/
Object & GetSpectator() const;
/* --------------------------------------------------------------------------------------------
* Set the managed player entity to spectate the specified player entity.
*/
void SetSpectator(CPlayer & target) const;
/* --------------------------------------------------------------------------------------------
* See whether the managed player entity is burning.
*/
bool IsBurning() const;
/* --------------------------------------------------------------------------------------------
* See whether the managed player entity is crouched.
*/
bool IsCrouched() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the current state of the managed player entity.
*/
Int32 GetState() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the current action of the managed player entity.
*/
Int32 GetAction() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the game keys of the managed player entity.
*/
Int32 GetGameKeys() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the aim position of the managed player entity.
*/
const Vector3 & GetAimPos() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the aim direction of the managed player entity.
*/
const Vector3 & GetAimDir() const;
/* --------------------------------------------------------------------------------------------
* Embark the managed player entity into the specified vehicle entity.
*/
void Embark(CVehicle & vehicle) const;
/* --------------------------------------------------------------------------------------------
* Embark the managed player entity into the specified vehicle entity.
*/
void Embark(CVehicle & vehicle, Int32 slot, bool allocate, bool warp) const;
/* --------------------------------------------------------------------------------------------
* Disembark the managed player entity from the currently embarked vehicle entity.
*/
void Disembark() const;
/* --------------------------------------------------------------------------------------------
* Redirect the managed player entity to the specified server.
*/
bool Redirect(CSStr ip, Uint32 port, CSStr nick, CSStr pass, CSStr user);
/* --------------------------------------------------------------------------------------------
* Retrieve the authority level of the managed player entity.
*/
Int32 GetAuthority() const;
/* --------------------------------------------------------------------------------------------
* Modify the authority level of the managed player entity.
*/
void SetAuthority(Int32 level) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the message prefix at the specified index for the managed player entity.
*/
CSStr GetMessagePrefix(Uint32 index) const;
/* --------------------------------------------------------------------------------------------
* Modify the message prefix at the specified index for the managed player entity.
*/
void SetMessagePrefix(Uint32 index, CSStr prefix) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the message color for the managed player entity.
*/
Uint32 GetMessageColor() const;
/* --------------------------------------------------------------------------------------------
* Modify the message color for the managed player entity.
*/
void SetMessageColor(Uint32 color) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the announcement style for the managed player entity.
*/
Int32 GetAnnounceStyle() const;
/* --------------------------------------------------------------------------------------------
* Modify the announcement style for the managed player entity.
*/
void SetAnnounceStyle(Int32 style) const;
// --------------------------------------------------------------------------------------------
/* --------------------------------------------------------------------------------------------
* Retrieve the position on the x axis of the managed player entity.
*/
Float32 GetPosX() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the position on the y axis of the managed player entity.
*/
Float32 GetPosY() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the position on the z axis of the managed player entity.
*/
Float32 GetPosZ() const;
/* --------------------------------------------------------------------------------------------
* Modify the position on the x axis of the managed player entity.
*/
void SetPosX(Float32 x) const;
/* --------------------------------------------------------------------------------------------
* Modify the position on the y axis of the managed player entity.
*/
void SetPosY(Float32 y) const;
/* --------------------------------------------------------------------------------------------
* Modify the position on the z axis of the managed player entity.
*/
void SetPosZ(Float32 z) const;
// --------------------------------------------------------------------------------------------
/* --------------------------------------------------------------------------------------------
* Send a formatted colored message to the managed player entity.
*/
static SQInteger Msg(HSQUIRRELVM vm);
static SQInteger MsgP(HSQUIRRELVM vm);
static SQInteger MsgEx(HSQUIRRELVM vm);
static SQInteger Message(HSQUIRRELVM vm);
static SQInteger Announce(HSQUIRRELVM vm);
static SQInteger AnnounceEx(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Send a formatted message with a prefix to the managed player entity.
*/
static SQInteger MsgP(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Send a formatted colored message to the managed player entity.
*/
static SQInteger MsgEx(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Send a formatted message to the managed player entity.
*/
static SQInteger Message(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Send a formatted announcement message to the managed player entity.
*/
static SQInteger Announce(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Send a formatted announcement message to the managed player entity.
*/
static SQInteger AnnounceEx(HSQUIRRELVM vm);
};
} // Namespace:: SqMod

View File

@ -8,15 +8,20 @@
namespace SqMod {
// ------------------------------------------------------------------------------------------------
SQChar CSprite::s_StrID[SQMOD_SPRITE_POOL][8];
const Int32 CSprite::Max = SQMOD_SPRITE_POOL;
// ------------------------------------------------------------------------------------------------
const Int32 CSprite::Max = SQMOD_SPRITE_POOL;
SQInteger CSprite::Typename(HSQUIRRELVM vm)
{
static SQChar name[] = _SC("SqSprite");
sq_pushstring(vm, name, sizeof(name));
return 1;
}
// ------------------------------------------------------------------------------------------------
CSprite::CSprite(Int32 id)
: m_ID(VALID_ENTITYGETEX(id, SQMOD_SPRITE_POOL))
, m_Tag(VALID_ENTITY(m_ID) ? s_StrID[m_ID] : _SC("-1"))
, m_Tag(ToStrF("%d", id))
{
/* ... */
}
@ -38,301 +43,407 @@ Int32 CSprite::Cmp(const CSprite & o) const
return -1;
}
CSStr CSprite::ToString() const
// ------------------------------------------------------------------------------------------------
const String & CSprite::ToString() const
{
return VALID_ENTITYEX(m_ID, SQMOD_SPRITE_POOL) ? s_StrID[m_ID] : _SC("-1");
return m_Tag;
}
// ------------------------------------------------------------------------------------------------
CSStr CSprite::GetTag() const
const String & CSprite::GetTag() const
{
return m_Tag.c_str();
return m_Tag;
}
// ------------------------------------------------------------------------------------------------
void CSprite::SetTag(CSStr tag)
{
m_Tag.assign(tag);
}
// ------------------------------------------------------------------------------------------------
Object & CSprite::GetData()
{
if (Validate())
return m_Data;
return NullObject();
// Validate the managed identifier
Validate();
// Return the requested information
return m_Data;
}
// ------------------------------------------------------------------------------------------------
void CSprite::SetData(Object & data)
{
if (Validate())
m_Data = data;
// Validate the managed identifier
Validate();
// Apply the specified value
m_Data = data;
}
// ------------------------------------------------------------------------------------------------
bool CSprite::Destroy(Int32 header, Object & payload)
{
// Validate the managed identifier
Validate();
// Perform the requested operation
return _Core->DelSprite(m_ID, header, payload);
}
// ------------------------------------------------------------------------------------------------
bool CSprite::BindEvent(Int32 evid, Object & env, Function & func) const
void CSprite::BindEvent(Int32 evid, Object & env, Function & func) const
{
if (!Validate())
return false;
// Validate the managed identifier
Validate();
// Obtain the function instance called for this event
Function & event = _Core->GetSpriteEvent(m_ID, evid);
// Is the specified callback function null?
if (func.IsNull())
event.Release();
event.Release(); // Then release the current callback
// Assign the specified environment and function
else
event = Function(env.GetVM(), env, func.GetFunc());
return true;
}
// ------------------------------------------------------------------------------------------------
void CSprite::ShowAll() const
{
if (Validate())
_Func->ShowSprite(m_ID, -1);
}
void CSprite::ShowFor(CPlayer & player) const
{
if (!player.IsActive())
SqThrow("Invalid player argument: null");
else if (Validate())
_Func->ShowSprite(m_ID, player.GetID());
}
void CSprite::ShowRange(Int32 first, Int32 last) const
{
if (first > last)
SqThrow("Invalid player range: %d > %d", first, last);
else if (Validate())
for (; first <= last; ++first)
{
if (_Func->IsPlayerConnected(first))
_Func->ShowSprite(m_ID, first);
}
}
void CSprite::HideAll() const
{
if (Validate())
_Func->HideSprite(m_ID, -1);
}
void CSprite::HideFor(CPlayer & player) const
{
if (!player.IsActive())
SqThrow("Invalid player argument: null");
else if (Validate())
_Func->HideSprite(m_ID, player.GetID());
}
void CSprite::HideRange(Int32 first, Int32 last) const
{
if (first > last)
SqThrow("Invalid player range: %d > %d", first, last);
else if (Validate())
for (; first <= last; ++first)
{
if (_Func->IsPlayerConnected(first))
_Func->HideSprite(m_ID, first);
}
}
void CSprite::SetPositionAll(const Vector2i & pos) const
{
if (Validate())
_Func->MoveSprite(m_ID, -1, pos.x, pos.y);
}
void CSprite::SetPositionAllEx(Int32 x, Int32 y) const
{
if (Validate())
_Func->MoveSprite(m_ID, -1, x, y);
}
void CSprite::SetPositionFor(CPlayer & player, const Vector2i & pos) const
{
if (!player.IsActive())
SqThrow("Invalid player argument: null");
else if (Validate())
_Func->MoveSprite(m_ID, player.GetID(), pos.x, pos.y);
}
void CSprite::SetPositionForEx(CPlayer & player, Int32 x, Int32 y) const
{
if (!player.IsActive())
SqThrow("Invalid player argument: null");
else if (Validate())
_Func->MoveSprite(m_ID, player.GetID(), x, y);
}
void CSprite::SetPositionRange(Int32 first, Int32 last, const Vector2i & pos) const
{
if (first > last)
SqThrow("Invalid player range: %d > %d", first, last);
else if (Validate())
for (; first <= last; ++first)
{
if (_Func->IsPlayerConnected(first))
_Func->MoveSprite(m_ID, first, pos.x, pos.y);
}
}
void CSprite::SetCenterAll(const Vector2i & pos) const
{
if (Validate())
_Func->SetSpriteCenter(m_ID, -1, pos.x, pos.y);
}
void CSprite::SetCenterAllEx(Int32 x, Int32 y) const
{
if (Validate())
_Func->SetSpriteCenter(m_ID, -1, x, y);
}
void CSprite::SetCenterFor(CPlayer & player, const Vector2i & pos) const
{
if (!player.IsActive())
SqThrow("Invalid player argument: null");
else if (Validate())
_Func->SetSpriteCenter(m_ID, player.GetID(), pos.x, pos.y);
}
void CSprite::SetCenterForEx(CPlayer & player, Int32 x, Int32 y) const
{
if (!player.IsActive())
SqThrow("Invalid player argument: null");
else if (Validate())
_Func->SetSpriteCenter(m_ID, player.GetID(), x, y);
}
void CSprite::SetCenterRange(Int32 first, Int32 last, const Vector2i & pos) const
{
if (first > last)
SqThrow("Invalid player range: %d > %d", first, last);
else if (Validate())
for (; first <= last; ++first)
{
if (_Func->IsPlayerConnected(first))
_Func->SetSpriteCenter(m_ID, first, pos.x, pos.y);
}
}
void CSprite::SetRotationAll(Float32 rot) const
{
if (Validate())
_Func->RotateSprite(m_ID, -1, rot);
}
void CSprite::SetRotationFor(CPlayer & player, Float32 rot) const
{
if (!player.IsActive())
SqThrow("Invalid player argument: null");
else if (Validate())
_Func->RotateSprite(m_ID, player.GetID(), rot);
}
void CSprite::SetRotationRange(Int32 first, Int32 last, Float32 rot) const
{
if (first > last)
SqThrow("Invalid player range: %d > %d", first, last);
else if (Validate())
for (; first <= last; ++first)
{
if (_Func->IsPlayerConnected(first))
_Func->RotateSprite(m_ID, first, rot);
}
}
void CSprite::SetAlphaAll(Uint8 alpha) const
{
if (Validate())
_Func->SetSpriteAlpha(m_ID, -1, alpha);
}
void CSprite::SetAlphaFor(CPlayer & player, Uint8 alpha) const
{
if (!player.IsActive())
SqThrow("Invalid player argument: null");
else if (Validate())
_Func->SetSpriteAlpha(m_ID, player.GetID(), alpha);
}
void CSprite::SetAlphaRange(Int32 first, Int32 last, Uint8 alpha) const
{
if (first > last)
SqThrow("Invalid player range: %d > %d", first, last);
else if (Validate())
for (; first <= last; ++first)
{
if (_Func->IsPlayerConnected(first))
_Func->SetSpriteAlpha(m_ID, first, alpha);
}
}
CSStr CSprite::GetFilePath() const
{
if (Validate())
_Core->GetSprite(m_ID).mPath.c_str();
return g_EmptyStr;
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->ShowSprite(m_ID, -1);
}
// ------------------------------------------------------------------------------------------------
static Object & CreateSpriteEx(CSStr file, Int32 xp, Int32 yp, Int32 xr, Int32 yr,
void CSprite::ShowFor(CPlayer & player) const
{
// Is the specified player even valid?
if (!player.IsActive())
SqThrowF("Invalid player argument: null");
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->ShowSprite(m_ID, player.GetID());
}
// ------------------------------------------------------------------------------------------------
void CSprite::ShowRange(Int32 first, Int32 last) const
{
// Validate the specified range
if (first > last)
SqThrowF("Invalid player range: %d > %d", first, last);
// Validate the managed identifier
Validate();
// Perform the requested operation
for (; first <= last; ++first)
{
// Is the currently processed player even connected?
if (_Func->IsPlayerConnected(first))
// Then show this textdraw on his client
_Func->ShowSprite(m_ID, first);
}
}
// ------------------------------------------------------------------------------------------------
void CSprite::HideAll() const
{
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->HideSprite(m_ID, -1);
}
// ------------------------------------------------------------------------------------------------
void CSprite::HideFor(CPlayer & player) const
{
// Is the specified player even valid?
if (!player.IsActive())
SqThrowF("Invalid player argument: null");
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->HideSprite(m_ID, player.GetID());
}
// ------------------------------------------------------------------------------------------------
void CSprite::HideRange(Int32 first, Int32 last) const
{
// Validate the specified range
if (first > last)
SqThrowF("Invalid player range: %d > %d", first, last);
// Validate the managed identifier
Validate();
// Perform the requested operation
for (; first <= last; ++first)
{
// Is the currently processed player even connected?
if (_Func->IsPlayerConnected(first))
// Then hide this textdraw on his client
_Func->HideSprite(m_ID, first);
}
}
// ------------------------------------------------------------------------------------------------
void CSprite::SetPositionAll(const Vector2i & pos) const
{
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->MoveSprite(m_ID, -1, pos.x, pos.y);
}
// ------------------------------------------------------------------------------------------------
void CSprite::SetPositionAllEx(Int32 x, Int32 y) const
{
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->MoveSprite(m_ID, -1, x, y);
}
// ------------------------------------------------------------------------------------------------
void CSprite::SetPositionFor(CPlayer & player, const Vector2i & pos) const
{
// Is the specified player even valid?
if (!player.IsActive())
SqThrowF("Invalid player argument: null");
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->MoveSprite(m_ID, player.GetID(), pos.x, pos.y);
}
// ------------------------------------------------------------------------------------------------
void CSprite::SetPositionForEx(CPlayer & player, Int32 x, Int32 y) const
{
// Is the specified player even valid?
if (!player.IsActive())
SqThrowF("Invalid player argument: null");
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->MoveSprite(m_ID, player.GetID(), x, y);
}
// ------------------------------------------------------------------------------------------------
void CSprite::SetPositionRange(Int32 first, Int32 last, const Vector2i & pos) const
{
// Validate the specified range
if (first > last)
SqThrowF("Invalid player range: %d > %d", first, last);
// Validate the managed identifier
Validate();
// Perform the requested operation
for (; first <= last; ++first)
{
// Is the currently processed player even connected?
if (_Func->IsPlayerConnected(first))
// Then move this textdraw on his client
_Func->MoveSprite(m_ID, first, pos.x, pos.y);
}
}
// ------------------------------------------------------------------------------------------------
void CSprite::SetCenterAll(const Vector2i & pos) const
{
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->SetSpriteCenter(m_ID, -1, pos.x, pos.y);
}
// ------------------------------------------------------------------------------------------------
void CSprite::SetCenterAllEx(Int32 x, Int32 y) const
{
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->SetSpriteCenter(m_ID, -1, x, y);
}
// ------------------------------------------------------------------------------------------------
void CSprite::SetCenterFor(CPlayer & player, const Vector2i & pos) const
{
// Is the specified player even valid?
if (!player.IsActive())
SqThrowF("Invalid player argument: null");
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->SetSpriteCenter(m_ID, player.GetID(), pos.x, pos.y);
}
// ------------------------------------------------------------------------------------------------
void CSprite::SetCenterForEx(CPlayer & player, Int32 x, Int32 y) const
{
// Is the specified player even valid?
if (!player.IsActive())
SqThrowF("Invalid player argument: null");
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->SetSpriteCenter(m_ID, player.GetID(), x, y);
}
// ------------------------------------------------------------------------------------------------
void CSprite::SetCenterRange(Int32 first, Int32 last, const Vector2i & pos) const
{
// Validate the specified range
if (first > last)
SqThrowF("Invalid player range: %d > %d", first, last);
// Validate the managed identifier
Validate();
// Perform the requested operation
for (; first <= last; ++first)
{
// Is the currently processed player even connected?
if (_Func->IsPlayerConnected(first))
// Then center this textdraw on his client
_Func->SetSpriteCenter(m_ID, first, pos.x, pos.y);
}
}
// ------------------------------------------------------------------------------------------------
void CSprite::SetRotationAll(Float32 rot) const
{
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->RotateSprite(m_ID, -1, rot);
}
// ------------------------------------------------------------------------------------------------
void CSprite::SetRotationFor(CPlayer & player, Float32 rot) const
{
// Is the specified player even valid?
if (!player.IsActive())
SqThrowF("Invalid player argument: null");
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->RotateSprite(m_ID, player.GetID(), rot);
}
// ------------------------------------------------------------------------------------------------
void CSprite::SetRotationRange(Int32 first, Int32 last, Float32 rot) const
{
// Validate the specified range
if (first > last)
SqThrowF("Invalid player range: %d > %d", first, last);
// Validate the managed identifier
Validate();
// Perform the requested operation
for (; first <= last; ++first)
{
// Is the currently processed player even connected?
if (_Func->IsPlayerConnected(first))
// Then rotate this textdraw on his client
_Func->RotateSprite(m_ID, first, rot);
}
}
// ------------------------------------------------------------------------------------------------
void CSprite::SetAlphaAll(Uint8 alpha) const
{
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->SetSpriteAlpha(m_ID, -1, alpha);
}
// ------------------------------------------------------------------------------------------------
void CSprite::SetAlphaFor(CPlayer & player, Uint8 alpha) const
{
// Is the specified player even valid?
if (!player.IsActive())
SqThrowF("Invalid player argument: null");
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->SetSpriteAlpha(m_ID, player.GetID(), alpha);
}
// ------------------------------------------------------------------------------------------------
void CSprite::SetAlphaRange(Int32 first, Int32 last, Uint8 alpha) const
{
// Validate the specified range
if (first > last)
SqThrowF("Invalid player range: %d > %d", first, last);
// Validate the managed identifier
Validate();
// Perform the requested operation
for (; first <= last; ++first)
{
// Is the currently processed player even connected?
if (_Func->IsPlayerConnected(first))
// Then colorize this textdraw on his client
_Func->SetSpriteAlpha(m_ID, first, alpha);
}
}
// ------------------------------------------------------------------------------------------------
const String & CSprite::GetFilePath() const
{
// Validate the managed identifier
Validate();
// Return the requested information
return _Core->GetSprite(m_ID).mPath;
}
// ------------------------------------------------------------------------------------------------
static Object & Sprite_CreateEx(CSStr file, Int32 xp, Int32 yp, Int32 xr, Int32 yr,
Float32 angle, Int32 alpha, bool rel)
{
return _Core->NewSprite(-1, file, xp, yp, xr, yr, angle, alpha, rel,
SQMOD_CREATE_DEFAULT, NullObject());
}
static Object & CreateSpriteEx(CSStr file, Int32 xp, Int32 yp, Int32 xr, Int32 yr,
// ------------------------------------------------------------------------------------------------
static Object & Sprite_CreateEx(CSStr file, Int32 xp, Int32 yp, Int32 xr, Int32 yr,
Float32 angle, Int32 alpha, bool rel, Int32 header, Object & payload)
{
return _Core->NewSprite(-1, file, xp, yp, xr, yr, angle, alpha, rel, header, payload);
}
// ------------------------------------------------------------------------------------------------
static Object & CreateSpriteEx(Int32 index, CSStr file, Int32 xp, Int32 yp, Int32 xr, Int32 yr,
static Object & Sprite_CreateEx(Int32 index, CSStr file, Int32 xp, Int32 yp, Int32 xr, Int32 yr,
Float32 angle, Int32 alpha, bool rel)
{
return _Core->NewSprite(index, file, xp, yp, xr, yr, angle, alpha, rel,
SQMOD_CREATE_DEFAULT, NullObject());
}
static Object & CreateSpriteEx(Int32 index, CSStr file, Int32 xp, Int32 yp, Int32 xr, Int32 yr,
// ------------------------------------------------------------------------------------------------
static Object & Sprite_CreateEx(Int32 index, CSStr file, Int32 xp, Int32 yp, Int32 xr, Int32 yr,
Float32 angle, Int32 alpha, bool rel, Int32 header, Object & payload)
{
return _Core->NewSprite(index, file, xp, yp, xr, yr, angle, alpha, rel, header, payload);
}
// ------------------------------------------------------------------------------------------------
static Object & CreateSprite(CSStr file, const Vector2i & pos, const Vector2i & rot,
static Object & Sprite_Create(CSStr file, const Vector2i & pos, const Vector2i & rot,
Float32 angle, Int32 alpha, bool rel)
{
return _Core->NewSprite(-1, file, pos.x, pos.y, rot.x, rot.y, angle, alpha, rel,
SQMOD_CREATE_DEFAULT, NullObject());
}
static Object & CreateSprite(CSStr file, const Vector2i & pos, const Vector2i & rot,
// ------------------------------------------------------------------------------------------------
static Object & Sprite_Create(CSStr file, const Vector2i & pos, const Vector2i & rot,
Float32 angle, Int32 alpha, bool rel, Int32 header, Object & payload)
{
return _Core->NewSprite(-1, file, pos.x, pos.y, rot.x, rot.y, angle, alpha, rel, header, payload);
}
// ------------------------------------------------------------------------------------------------
static Object & CreateSprite(Int32 index, CSStr file, const Vector2i & pos, const Vector2i & rot,
static Object & Sprite_Create(Int32 index, CSStr file, const Vector2i & pos, const Vector2i & rot,
Float32 angle, Int32 alpha, bool rel)
{
return _Core->NewSprite(index, file, pos.x, pos.y, rot.x, rot.y, angle, alpha, rel,
SQMOD_CREATE_DEFAULT, NullObject());
}
static Object & CreateSprite(Int32 index, CSStr file, const Vector2i & pos, const Vector2i & rot,
// ------------------------------------------------------------------------------------------------
static Object & Sprite_Create(Int32 index, CSStr file, const Vector2i & pos, const Vector2i & rot,
Float32 angle, Int32 alpha, bool rel, Int32 header, Object & payload)
{
return _Core->NewSprite(index, file, pos.x, pos.y, rot.x, rot.y, angle, alpha, rel, header, payload);
@ -343,24 +454,26 @@ void Register_CSprite(HSQUIRRELVM vm)
{
RootTable(vm).Bind(_SC("SqSprite"),
Class< CSprite, NoConstructor< CSprite > >(vm, _SC("SqSprite"))
/* Metamethods */
// Metamethods
.Func(_SC("_cmp"), &CSprite::Cmp)
.SquirrelFunc(_SC("_typename"), &CSprite::Typename)
.Func(_SC("_tostring"), &CSprite::ToString)
/* Core Properties */
// Static values
.SetStaticValue(_SC("MaxID"), CSprite::Max)
// Core Properties
.Prop(_SC("ID"), &CSprite::GetID)
.Prop(_SC("Tag"), &CSprite::GetTag, &CSprite::SetTag)
.Prop(_SC("Data"), &CSprite::GetData, &CSprite::SetData)
.Prop(_SC("MaxID"), &CSprite::GetMaxID)
.Prop(_SC("Active"), &CSprite::IsActive)
/* Core Functions */
// Core Functions
.Func(_SC("Bind"), &CSprite::BindEvent)
/* Core Overloads */
// Core Overloads
.Overload< bool (CSprite::*)(void) >(_SC("Destroy"), &CSprite::Destroy)
.Overload< bool (CSprite::*)(Int32) >(_SC("Destroy"), &CSprite::Destroy)
.Overload< bool (CSprite::*)(Int32, Object &) >(_SC("Destroy"), &CSprite::Destroy)
/* Properties */
// Properties
.Prop(_SC("Path"), &CSprite::GetFilePath)
/* Functions */
// Functions
.Func(_SC("ShowAll"), &CSprite::ShowAll)
.Func(_SC("ShowTo"), &CSprite::ShowFor)
.Func(_SC("ShowFor"), &CSprite::ShowFor)
@ -377,7 +490,7 @@ void Register_CSprite(HSQUIRRELVM vm)
.Func(_SC("SetAlphaAll"), &CSprite::SetAlphaAll)
.Func(_SC("SetAlphaFor"), &CSprite::SetAlphaFor)
.Func(_SC("SetAlphaRange"), &CSprite::SetAlphaRange)
/* Overloads */
// Overloads
.Overload< void (CSprite::*)(const Vector2i &) const >
(_SC("SetPositionAll"), &CSprite::SetPositionAll)
.Overload< void (CSprite::*)(Int32, Int32) const >
@ -394,25 +507,24 @@ void Register_CSprite(HSQUIRRELVM vm)
(_SC("SetCenterFor"), &CSprite::SetCenterFor)
.Overload< void (CSprite::*)(CPlayer &, Int32, Int32) const >
(_SC("SetCenterFor"), &CSprite::SetCenterForEx)
// Static Overloads
.StaticOverload< Object & (*)(CSStr, Int32, Int32, Int32, Int32, Float32, Int32, bool rel) >
(_SC("CreateEx"), &Sprite_CreateEx)
.StaticOverload< Object & (*)(CSStr, Int32, Int32, Int32, Int32, Float32, Int32, bool rel, Int32, Object &) >
(_SC("CreateEx"), &Sprite_CreateEx)
.StaticOverload< Object & (*)(Int32, CSStr, Int32, Int32, Int32, Int32, Float32, Int32, bool rel) >
(_SC("CreateEx"), &Sprite_CreateEx)
.StaticOverload< Object & (*)(Int32, CSStr, Int32, Int32, Int32, Int32, Float32, Int32, bool rel, Int32, Object &) >
(_SC("CreateEx"), &Sprite_CreateEx)
.StaticOverload< Object & (*)(CSStr, const Vector2i &, const Vector2i &, Float32, Int32, bool) >
(_SC("Create"), &Sprite_Create)
.StaticOverload< Object & (*)(CSStr, const Vector2i &, const Vector2i &, Float32, Int32, bool, Int32, Object &) >
(_SC("Create"), &Sprite_Create)
.StaticOverload< Object & (*)(Int32, CSStr, const Vector2i &, const Vector2i &, Float32, Int32, bool) >
(_SC("Create"), &Sprite_Create)
.StaticOverload< Object & (*)(Int32, CSStr, const Vector2i &, const Vector2i &, Float32, Int32, bool, Int32, Object &) >
(_SC("Create"), &Sprite_Create)
);
RootTable(vm)
.Overload< Object & (*)(CSStr, Int32, Int32, Int32, Int32, Float32, Int32, bool rel) >
(_SC("CreateSpriteEx"), &CreateSpriteEx)
.Overload< Object & (*)(CSStr, Int32, Int32, Int32, Int32, Float32, Int32, bool rel, Int32, Object &) >
(_SC("CreateSpriteEx"), &CreateSpriteEx)
.Overload< Object & (*)(Int32, CSStr, Int32, Int32, Int32, Int32, Float32, Int32, bool rel) >
(_SC("CreateSpriteEx"), &CreateSpriteEx)
.Overload< Object & (*)(Int32, CSStr, Int32, Int32, Int32, Int32, Float32, Int32, bool rel, Int32, Object &) >
(_SC("CreateSpriteEx"), &CreateSpriteEx)
.Overload< Object & (*)(CSStr, const Vector2i &, const Vector2i &, Float32, Int32, bool) >
(_SC("CreateSprite"), &CreateSprite)
.Overload< Object & (*)(CSStr, const Vector2i &, const Vector2i &, Float32, Int32, bool, Int32, Object &) >
(_SC("CreateSprite"), &CreateSprite)
.Overload< Object & (*)(Int32, CSStr, const Vector2i &, const Vector2i &, Float32, Int32, bool) >
(_SC("CreateSprite"), &CreateSprite)
.Overload< Object & (*)(Int32, CSStr, const Vector2i &, const Vector2i &, Float32, Int32, bool, Int32, Object &) >
(_SC("CreateSprite"), &CreateSprite);
}
} // Namespace:: SqMod
} // Namespace:: SqMod

View File

@ -8,7 +8,7 @@
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Manages Sprite instances.
* Manages a single sprite entity.
*/
class CSprite
{
@ -17,20 +17,19 @@ class CSprite
private:
/* --------------------------------------------------------------------------------------------
* Cached identifiers for fast integer to string conversion.
*/
static SQChar s_StrID[SQMOD_SPRITE_POOL][8];
/* --------------------------------------------------------------------------------------------
* Identifier of the managed entity.
*/
Int32 m_ID;
/* --------------------------------------------------------------------------------------------
* User tag and data associated with this instance.
* User tag associated with this instance.
*/
String m_Tag;
/* --------------------------------------------------------------------------------------------
* User data associated with this instance.
*/
Object m_Data;
/* --------------------------------------------------------------------------------------------
@ -38,35 +37,45 @@ private:
*/
CSprite(Int32 id);
public:
/* --------------------------------------------------------------------------------------------
* Maximum possible number that could represent an identifier for this entity type.
*/
static const Int32 Max;
/* --------------------------------------------------------------------------------------------
* Copy constructor. (disabled)
*/
CSprite(const CSprite &);
CSprite(const CSprite &) = delete;
/* --------------------------------------------------------------------------------------------
* Copy assignment operator. (disabled)
* Move constructor. (disabled)
*/
CSprite & operator = (const CSprite &);
public:
// --------------------------------------------------------------------------------------------
static const Int32 Max;
CSprite(CSprite &&) = delete;
/* --------------------------------------------------------------------------------------------
* Destructor.
*/
~CSprite();
/* --------------------------------------------------------------------------------------------
* Copy assignment operator. (disabled)
*/
CSprite & operator = (const CSprite &) = delete;
/* --------------------------------------------------------------------------------------------
* Move assignment operator. (disabled)
*/
CSprite & operator = (CSprite &&) = delete;
/* --------------------------------------------------------------------------------------------
* See whether this instance manages a valid entity.
*/
bool Validate() const
void Validate() const
{
if (VALID_ENTITY(m_ID))
return true;
SqThrow("Invalid sprite reference [%s]", m_Tag.c_str());
return false;
if (INVALID_ENTITY(m_ID))
SqThrowF("Invalid sprite reference [%s]", m_Tag.c_str());
}
/* --------------------------------------------------------------------------------------------
@ -77,27 +86,33 @@ public:
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
CSStr ToString() const;
const String & ToString() const;
/* --------------------------------------------------------------------------------------------
* Used by the script engine to retrieve the name from instances of this type.
*/
static SQInteger Typename(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Retrieve the identifier of the entity managed by this instance.
*/
Int32 GetID() const { return m_ID; }
/* --------------------------------------------------------------------------------------------
* Retrieve the maximum possible identifier to an entity of this type.
*/
Int32 GetMaxID() const { return SQMOD_SPRITE_POOL; }
Int32 GetID() const
{
return m_ID;
}
/* --------------------------------------------------------------------------------------------
* Check whether this instance manages a valid entity.
*/
bool IsActive() const { return VALID_ENTITY(m_ID); }
bool IsActive() const
{
return VALID_ENTITY(m_ID);
}
/* --------------------------------------------------------------------------------------------
* Retrieve the associated user tag.
*/
CSStr GetTag() const;
const String & GetTag() const;
/* --------------------------------------------------------------------------------------------
* Modify the associated user tag.
@ -114,38 +129,146 @@ public:
*/
void SetData(Object & data);
// --------------------------------------------------------------------------------------------
/* --------------------------------------------------------------------------------------------
* Destroy the managed sprite entity.
*/
bool Destroy()
{
return Destroy(0, NullObject());
}
/* --------------------------------------------------------------------------------------------
* Destroy the managed sprite entity.
*/
bool Destroy(Int32 header)
{
return Destroy(header, NullObject());
}
/* --------------------------------------------------------------------------------------------
* Destroy the managed sprite entity.
*/
bool Destroy(Int32 header, Object & payload);
bool Destroy() { return Destroy(0, NullObject()); }
bool Destroy(Int32 header) { return Destroy(header, NullObject()); }
// --------------------------------------------------------------------------------------------
bool BindEvent(Int32 evid, Object & env, Function & func) const;
/* --------------------------------------------------------------------------------------------
* Bind to an event supported by this entity type.
*/
void BindEvent(Int32 evid, Object & env, Function & func) const;
// --------------------------------------------------------------------------------------------
/* --------------------------------------------------------------------------------------------
* Show the managed sprite entity to all players on the server.
*/
void ShowAll() const;
/* --------------------------------------------------------------------------------------------
* Show the managed sprite entity to the specified player entity.
*/
void ShowFor(CPlayer & player) const;
/* --------------------------------------------------------------------------------------------
* Show the managed sprite entity to all players in the specified range.
*/
void ShowRange(Int32 first, Int32 last) const;
/* --------------------------------------------------------------------------------------------
* Hide the managed sprite entity from all players on the server.
*/
void HideAll() const;
/* --------------------------------------------------------------------------------------------
* Hide the managed sprite entity from the specified player entity.
*/
void HideFor(CPlayer & player) const;
/* --------------------------------------------------------------------------------------------
* Hide the managed sprite entity from all players in the specified range.
*/
void HideRange(Int32 first, Int32 last) const;
/* --------------------------------------------------------------------------------------------
* Set the position of the managed sprite entity for all players on the server.
*/
void SetPositionAll(const Vector2i & pos) const;
/* --------------------------------------------------------------------------------------------
* Set the position of the managed sprite entity for all players on the server.
*/
void SetPositionAllEx(Int32 x, Int32 y) const;
/* --------------------------------------------------------------------------------------------
* Set the position of the managed sprite entity for the specified player entity.
*/
void SetPositionFor(CPlayer & player, const Vector2i & pos) const;
/* --------------------------------------------------------------------------------------------
* Set the position of the managed sprite entity for the specified player entity.
*/
void SetPositionForEx(CPlayer & player, Int32 x, Int32 y) const;
/* --------------------------------------------------------------------------------------------
* Set the position of the managed sprite entity for all players in the specified range.
*/
void SetPositionRange(Int32 first, Int32 last, const Vector2i & pos) const;
/* --------------------------------------------------------------------------------------------
* Set the center of the managed sprite entity for all players on the server.
*/
void SetCenterAll(const Vector2i & pos) const;
/* --------------------------------------------------------------------------------------------
* Set the center of the managed sprite entity for all players on the server.
*/
void SetCenterAllEx(Int32 x, Int32 y) const;
/* --------------------------------------------------------------------------------------------
* Set the center of the managed sprite entity for the specified player entity.
*/
void SetCenterFor(CPlayer & player, const Vector2i & pos) const;
/* --------------------------------------------------------------------------------------------
* Set the center of the managed sprite entity for the specified player entity.
*/
void SetCenterForEx(CPlayer & player, Int32 x, Int32 y) const;
/* --------------------------------------------------------------------------------------------
* Set the center of the managed sprite entity for all players in the specified range.
*/
void SetCenterRange(Int32 first, Int32 last, const Vector2i & pos) const;
void SetRotationAll(SQFloat rot) const;
void SetRotationFor(CPlayer & player, SQFloat rot) const;
void SetRotationRange(Int32 first, Int32 last, SQFloat rot) const;
/* --------------------------------------------------------------------------------------------
* Set the rotation of the managed sprite entity for all players on the server.
*/
void SetRotationAll(Float32 rot) const;
/* --------------------------------------------------------------------------------------------
* Set the rotation of the managed sprite entity for the specified player entity.
*/
void SetRotationFor(CPlayer & player, Float32 rot) const;
/* --------------------------------------------------------------------------------------------
* Set the rotation of the managed sprite entity for all players in the specified range.
*/
void SetRotationRange(Int32 first, Int32 last, Float32 rot) const;
/* --------------------------------------------------------------------------------------------
* Set the alpha of the managed sprite entity for all players on the server.
*/
void SetAlphaAll(Uint8 alpha) const;
/* --------------------------------------------------------------------------------------------
* Set the alpha of the managed sprite entity for the specified player entity.
*/
void SetAlphaFor(CPlayer & player, Uint8 alpha) const;
/* --------------------------------------------------------------------------------------------
* Set the alpha of the managed sprite entity for all players in the specified range.
*/
void SetAlphaRange(Int32 first, Int32 last, Uint8 alpha) const;
CSStr GetFilePath() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the file path of the texture used by the managed sprite entity.
*/
const String & GetFilePath() const;
};
} // Namespace:: SqMod

View File

@ -8,15 +8,20 @@
namespace SqMod {
// ------------------------------------------------------------------------------------------------
SQChar CTextdraw::s_StrID[SQMOD_TEXTDRAW_POOL][8];
const Int32 CTextdraw::Max = SQMOD_TEXTDRAW_POOL;
// ------------------------------------------------------------------------------------------------
const Int32 CTextdraw::Max = SQMOD_TEXTDRAW_POOL;
SQInteger CTextdraw::Typename(HSQUIRRELVM vm)
{
static SQChar name[] = _SC("SqTextdraw");
sq_pushstring(vm, name, sizeof(name));
return 1;
}
// ------------------------------------------------------------------------------------------------
CTextdraw::CTextdraw(Int32 id)
: m_ID(VALID_ENTITYGETEX(id, SQMOD_TEXTDRAW_POOL))
, m_Tag(VALID_ENTITY(m_ID) ? s_StrID[m_ID] : _SC("-1"))
, m_Tag(ToStrF("%d", id))
{
/* ... */
}
@ -38,206 +43,283 @@ Int32 CTextdraw::Cmp(const CTextdraw & o) const
return -1;
}
CSStr CTextdraw::ToString() const
// ------------------------------------------------------------------------------------------------
const String & CTextdraw::ToString() const
{
return VALID_ENTITYEX(m_ID, SQMOD_TEXTDRAW_POOL) ? s_StrID[m_ID] : _SC("-1");
return m_Tag;
}
// ------------------------------------------------------------------------------------------------
CSStr CTextdraw::GetTag() const
const String & CTextdraw::GetTag() const
{
return m_Tag.c_str();
return m_Tag;
}
// ------------------------------------------------------------------------------------------------
void CTextdraw::SetTag(CSStr tag)
{
m_Tag.assign(tag);
}
// ------------------------------------------------------------------------------------------------
Object & CTextdraw::GetData()
{
if (Validate())
return m_Data;
return NullObject();
// Validate the managed identifier
Validate();
// Return the requested information
return m_Data;
}
// ------------------------------------------------------------------------------------------------
void CTextdraw::SetData(Object & data)
{
if (Validate())
m_Data = data;
// Validate the managed identifier
Validate();
// Apply the specified value
m_Data = data;
}
// ------------------------------------------------------------------------------------------------
bool CTextdraw::Destroy(Int32 header, Object & payload)
{
// Validate the managed identifier
Validate();
// Perform the requested operation
return _Core->DelTextdraw(m_ID, header, payload);
}
// ------------------------------------------------------------------------------------------------
bool CTextdraw::BindEvent(Int32 evid, Object & env, Function & func) const
void CTextdraw::BindEvent(Int32 evid, Object & env, Function & func) const
{
if (!Validate())
return false;
// Validate the managed identifier
Validate();
// Obtain the function instance called for this event
Function & event = _Core->GetTextdrawEvent(m_ID, evid);
// Is the specified callback function null?
if (func.IsNull())
event.Release();
event.Release(); // Then release the current callback
// Assign the specified environment and function
else
event = Function(env.GetVM(), env, func.GetFunc());
return true;
}
// ------------------------------------------------------------------------------------------------
void CTextdraw::ShowAll() const
{
if (Validate())
_Func->ShowTextdraw(m_ID, -1);
}
void CTextdraw::ShowFor(CPlayer & player) const
{
if (!player.IsActive())
SqThrow("Invalid player argument: null");
else if (Validate())
_Func->ShowTextdraw(m_ID, player.GetID());
}
void CTextdraw::ShowRange(Int32 first, Int32 last) const
{
if (first > last)
SqThrow("Invalid player range: %d > %d", first, last);
else if (Validate())
for (; first <= last; ++first)
{
if (_Func->IsPlayerConnected(first))
_Func->ShowTextdraw(m_ID, first);
}
}
void CTextdraw::HideAll() const
{
if (Validate())
_Func->HideTextdraw(m_ID, -1);
}
void CTextdraw::HideFor(CPlayer & player) const
{
if (!player.IsActive())
SqThrow("Invalid player argument: null");
else if (Validate())
_Func->HideTextdraw(m_ID, player.GetID());
}
void CTextdraw::HideRange(Int32 first, Int32 last) const
{
if (first > last)
SqThrow("Invalid player range: %d > %d", first, last);
else if (Validate())
for (; first <= last; ++first)
{
if (_Func->IsPlayerConnected(first))
_Func->HideTextdraw(m_ID, first);
}
}
void CTextdraw::SetPositionAll(const Vector2i & pos) const
{
if (Validate())
_Func->MoveTextdraw(m_ID, -1, pos.x, pos.y);
}
void CTextdraw::SetPositionAllEx(Int32 x, Int32 y) const
{
if (Validate())
_Func->MoveTextdraw(m_ID, -1, x, y);
}
void CTextdraw::SetPositionFor(CPlayer & player, const Vector2i & pos) const
{
if (!player.IsActive())
SqThrow("Invalid player argument: null");
else if (Validate())
_Func->MoveTextdraw(m_ID, player.GetID(), pos.x, pos.y);
}
void CTextdraw::SetPositionForEx(CPlayer & player, Int32 x, Int32 y) const
{
if (!player.IsActive())
SqThrow("Invalid player argument: null");
else if (Validate())
_Func->MoveTextdraw(m_ID, player.GetID(), x, y);
}
void CTextdraw::SetPositionRange(Int32 first, Int32 last, const Vector2i & pos) const
{
if (first > last)
SqThrow("Invalid player range: %d > %d", first, last);
else if (Validate())
for (; first <= last; ++first)
{
if (_Func->IsPlayerConnected(first))
_Func->MoveTextdraw(m_ID, first, pos.x, pos.y);
}
}
void CTextdraw::SetColorAll(const Color4 & col) const
{
if (Validate())
_Func->SetTextdrawColour(m_ID, -1, col.GetRGBA());
}
void CTextdraw::SetColorAllEx(Uint8 r, Uint8 g, Uint8 b, Uint8 a) const
{
if (Validate())
_Func->SetTextdrawColour(m_ID, -1, SQMOD_PACK_RGBA(r, g, b, a));
}
void CTextdraw::SetColorFor(CPlayer & player, const Color4 & col) const
{
if (!player.IsActive())
SqThrow("Invalid player argument: null");
else if (Validate())
_Func->SetTextdrawColour(m_ID, player.GetID(), col.GetRGBA());
}
void CTextdraw::SetColorForEx(CPlayer & player, Uint8 r, Uint8 g, Uint8 b, Uint8 a) const
{
if (!player.IsActive())
SqThrow("Invalid player argument: null");
else if (Validate())
_Func->SetTextdrawColour(m_ID, player.GetID(), SQMOD_PACK_RGBA(r, g, b, a));
}
void CTextdraw::SetColorRange(Int32 first, Int32 last, const Color4 & col) const
{
if (first > last)
SqThrow("Invalid player range: %d > %d", first, last);
else if (Validate())
for (const Uint32 color = col.GetRGBA(); first <= last; ++first)
{
if (_Func->IsPlayerConnected(first))
_Func->SetTextdrawColour(m_ID, first, color);
}
}
CSStr CTextdraw::GetText() const
{
if (Validate())
_Core->GetTextdraw(m_ID).mText.c_str();
return g_EmptyStr;
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->ShowTextdraw(m_ID, -1);
}
// ------------------------------------------------------------------------------------------------
static Object & CreateTextdrawEx(CSStr text, Int32 xp, Int32 yp,
void CTextdraw::ShowFor(CPlayer & player) const
{
// Is the specified player even valid?
if (!player.IsActive())
SqThrowF("Invalid player argument: null");
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->ShowTextdraw(m_ID, player.GetID());
}
// ------------------------------------------------------------------------------------------------
void CTextdraw::ShowRange(Int32 first, Int32 last) const
{
// Validate the specified range
if (first > last)
SqThrowF("Invalid player range: %d > %d", first, last);
// Validate the managed identifier
Validate();
// Perform the requested operation
for (; first <= last; ++first)
{
// Is the currently processed player even connected?
if (_Func->IsPlayerConnected(first))
// Then show this textdraw on his client
_Func->ShowTextdraw(m_ID, first);
}
}
// ------------------------------------------------------------------------------------------------
void CTextdraw::HideAll() const
{
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->HideTextdraw(m_ID, -1);
}
// ------------------------------------------------------------------------------------------------
void CTextdraw::HideFor(CPlayer & player) const
{
// Is the specified player even valid?
if (!player.IsActive())
SqThrowF("Invalid player argument: null");
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->HideTextdraw(m_ID, player.GetID());
}
// ------------------------------------------------------------------------------------------------
void CTextdraw::HideRange(Int32 first, Int32 last) const
{
// Validate the specified range
if (first > last)
SqThrowF("Invalid player range: %d > %d", first, last);
// Validate the managed identifier
Validate();
// Perform the requested operation
for (; first <= last; ++first)
{
// Is the currently processed player even connected?
if (_Func->IsPlayerConnected(first))
// Then hide this textdraw on his client
_Func->HideTextdraw(m_ID, first);
}
}
// ------------------------------------------------------------------------------------------------
void CTextdraw::SetPositionAll(const Vector2i & pos) const
{
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->MoveTextdraw(m_ID, -1, pos.x, pos.y);
}
// ------------------------------------------------------------------------------------------------
void CTextdraw::SetPositionAllEx(Int32 x, Int32 y) const
{
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->MoveTextdraw(m_ID, -1, x, y);
}
// ------------------------------------------------------------------------------------------------
void CTextdraw::SetPositionFor(CPlayer & player, const Vector2i & pos) const
{
// Is the specified player even valid?
if (!player.IsActive())
SqThrowF("Invalid player argument: null");
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->MoveTextdraw(m_ID, player.GetID(), pos.x, pos.y);
}
// ------------------------------------------------------------------------------------------------
void CTextdraw::SetPositionForEx(CPlayer & player, Int32 x, Int32 y) const
{
// Is the specified player even valid?
if (!player.IsActive())
SqThrowF("Invalid player argument: null");
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->MoveTextdraw(m_ID, player.GetID(), x, y);
}
// ------------------------------------------------------------------------------------------------
void CTextdraw::SetPositionRange(Int32 first, Int32 last, const Vector2i & pos) const
{
// Validate the specified range
if (first > last)
SqThrowF("Invalid player range: %d > %d", first, last);
// Validate the managed identifier
Validate();
// Perform the requested operation
for (; first <= last; ++first)
{
// Is the currently processed player even connected?
if (_Func->IsPlayerConnected(first))
// Then move this textdraw on his client
_Func->MoveTextdraw(m_ID, first, pos.x, pos.y);
}
}
// ------------------------------------------------------------------------------------------------
void CTextdraw::SetColorAll(const Color4 & col) const
{
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->SetTextdrawColour(m_ID, -1, col.GetRGBA());
}
// ------------------------------------------------------------------------------------------------
void CTextdraw::SetColorAllEx(Uint8 r, Uint8 g, Uint8 b, Uint8 a) const
{
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->SetTextdrawColour(m_ID, -1, SQMOD_PACK_RGBA(r, g, b, a));
}
// ------------------------------------------------------------------------------------------------
void CTextdraw::SetColorFor(CPlayer & player, const Color4 & col) const
{
// Is the specified player even valid?
if (!player.IsActive())
SqThrowF("Invalid player argument: null");
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->SetTextdrawColour(m_ID, player.GetID(), col.GetRGBA());
}
// ------------------------------------------------------------------------------------------------
void CTextdraw::SetColorForEx(CPlayer & player, Uint8 r, Uint8 g, Uint8 b, Uint8 a) const
{
// Is the specified player even valid?
if (!player.IsActive())
SqThrowF("Invalid player argument: null");
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->SetTextdrawColour(m_ID, player.GetID(), SQMOD_PACK_RGBA(r, g, b, a));
}
// ------------------------------------------------------------------------------------------------
void CTextdraw::SetColorRange(Int32 first, Int32 last, const Color4 & col) const
{
// Validate the specified range
if (first > last)
SqThrowF("Invalid player range: %d > %d", first, last);
// Validate the managed identifier
Validate();
// Perform the requested operation
for (const Uint32 color = col.GetRGBA(); first <= last; ++first)
{
// Is the currently processed player even connected?
if (_Func->IsPlayerConnected(first))
// Then colorize this textdraw on his client
_Func->SetTextdrawColour(m_ID, first, color);
}
}
// ------------------------------------------------------------------------------------------------
const String & CTextdraw::GetText() const
{
// Validate the managed identifier
Validate();
// Return the requested information
return _Core->GetTextdraw(m_ID).mText;
}
// ------------------------------------------------------------------------------------------------
static Object & Textdraw_CreateEx(CSStr text, Int32 xp, Int32 yp,
Uint8 r, Uint8 g, Uint8 b, Uint8 a, bool rel)
{
return _Core->NewTextdraw(SQMOD_UNKNOWN, text, xp, yp, SQMOD_PACK_ARGB(a, r, g, b), rel,
SQMOD_CREATE_DEFAULT, NullObject());
}
static Object & CreateTextdrawEx(CSStr text, Int32 xp, Int32 yp,
// ------------------------------------------------------------------------------------------------
static Object & Textdraw_CreateEx(CSStr text, Int32 xp, Int32 yp,
Uint8 r, Uint8 g, Uint8 b, Uint8 a, bool rel,
Int32 header, Object & payload)
{
@ -246,14 +328,15 @@ static Object & CreateTextdrawEx(CSStr text, Int32 xp, Int32 yp,
}
// ------------------------------------------------------------------------------------------------
static Object & CreateTextdrawEx(Int32 index, CSStr text, Int32 xp, Int32 yp,
static Object & Textdraw_CreateEx(Int32 index, CSStr text, Int32 xp, Int32 yp,
Uint8 r, Uint8 g, Uint8 b, Uint8 a, bool rel)
{
return _Core->NewTextdraw(index,text, xp, yp, SQMOD_PACK_ARGB(a, r, g, b), rel,
SQMOD_CREATE_DEFAULT, NullObject());
}
static Object & CreateTextdrawEx(Int32 index, CSStr text, Int32 xp, Int32 yp,
// ------------------------------------------------------------------------------------------------
static Object & Textdraw_CreateEx(Int32 index, CSStr text, Int32 xp, Int32 yp,
Uint8 r, Uint8 g, Uint8 b, Uint8 a, bool rel,
Int32 header, Object & payload)
{
@ -262,13 +345,14 @@ static Object & CreateTextdrawEx(Int32 index, CSStr text, Int32 xp, Int32 yp,
}
// ------------------------------------------------------------------------------------------------
static Object & CreateTextdraw(CSStr text, const Vector2i & pos, const Color4 & color, bool rel)
static Object & Textdraw_Create(CSStr text, const Vector2i & pos, const Color4 & color, bool rel)
{
return _Core->NewTextdraw(SQMOD_UNKNOWN, text, pos.x, pos.y, color.GetARGB(), rel,
SQMOD_CREATE_DEFAULT, NullObject());
}
static Object & CreateTextdraw(CSStr text, const Vector2i & pos, const Color4 & color, bool rel,
// ------------------------------------------------------------------------------------------------
static Object & Textdraw_Create(CSStr text, const Vector2i & pos, const Color4 & color, bool rel,
Int32 header, Object & payload)
{
return _Core->NewTextdraw(SQMOD_UNKNOWN, text, pos.x, pos.y, color.GetARGB(), rel,
@ -276,14 +360,15 @@ static Object & CreateTextdraw(CSStr text, const Vector2i & pos, const Color4 &
}
// ------------------------------------------------------------------------------------------------
static Object & CreateTextdraw(Int32 index, CSStr text, const Vector2i & pos, const Color4 & color,
static Object & Textdraw_Create(Int32 index, CSStr text, const Vector2i & pos, const Color4 & color,
bool rel)
{
return _Core->NewTextdraw(index, text, pos.x, pos.y, color.GetARGB(), rel,
SQMOD_CREATE_DEFAULT, NullObject());
}
static Object & CreateTextdraw(Int32 index, CSStr text, const Vector2i & pos, const Color4 & color,
// ------------------------------------------------------------------------------------------------
static Object & Textdraw_Create(Int32 index, CSStr text, const Vector2i & pos, const Color4 & color,
bool rel, Int32 header, Object & payload)
{
return _Core->NewTextdraw(index, text, pos.x, pos.y, color.GetARGB(), rel, header, payload);
@ -294,24 +379,26 @@ void Register_CTextdraw(HSQUIRRELVM vm)
{
RootTable(vm).Bind(_SC("SqTextdraw"),
Class< CTextdraw, NoConstructor< CTextdraw > >(vm, _SC("SqTextdraw"))
/* Metamethods */
// Metamethods
.Func(_SC("_cmp"), &CTextdraw::Cmp)
.SquirrelFunc(_SC("_typename"), &CTextdraw::Typename)
.Func(_SC("_tostring"), &CTextdraw::ToString)
/* Core Properties */
// Static values
.SetStaticValue(_SC("MaxID"), CTextdraw::Max)
// Core Properties
.Prop(_SC("ID"), &CTextdraw::GetID)
.Prop(_SC("Tag"), &CTextdraw::GetTag, &CTextdraw::SetTag)
.Prop(_SC("Data"), &CTextdraw::GetData, &CTextdraw::SetData)
.Prop(_SC("MaxID"), &CTextdraw::GetMaxID)
.Prop(_SC("Active"), &CTextdraw::IsActive)
/* Core Functions */
// Core Functions
.Func(_SC("Bind"), &CTextdraw::BindEvent)
/* Core Overloads */
// Core Overloads
.Overload< bool (CTextdraw::*)(void) >(_SC("Destroy"), &CTextdraw::Destroy)
.Overload< bool (CTextdraw::*)(Int32) >(_SC("Destroy"), &CTextdraw::Destroy)
.Overload< bool (CTextdraw::*)(Int32, Object &) >(_SC("Destroy"), &CTextdraw::Destroy)
/* Properties */
// Properties
.Prop(_SC("Text"), &CTextdraw::GetText)
/* Functions */
// Functions
.Func(_SC("ShowAll"), &CTextdraw::ShowAll)
.Func(_SC("ShowTo"), &CTextdraw::ShowFor)
.Func(_SC("ShowFor"), &CTextdraw::ShowFor)
@ -322,7 +409,7 @@ void Register_CTextdraw(HSQUIRRELVM vm)
.Func(_SC("HideRange"), &CTextdraw::HideRange)
.Func(_SC("SetPositionRange"), &CTextdraw::SetPositionRange)
.Func(_SC("SetColorRange"), &CTextdraw::SetColorRange)
/* Overloads */
// Overloads
.Overload< void (CTextdraw::*)(const Vector2i &) const >
(_SC("SetPositionAll"), &CTextdraw::SetPositionAll)
.Overload< void (CTextdraw::*)(Int32, Int32) const >
@ -339,25 +426,24 @@ void Register_CTextdraw(HSQUIRRELVM vm)
(_SC("SetColorFor"), &CTextdraw::SetColorFor)
.Overload< void (CTextdraw::*)(CPlayer &, Uint8, Uint8, Uint8, Uint8) const >
(_SC("SetColorFor"), &CTextdraw::SetColorForEx)
// Static Overloads
.StaticOverload< Object & (*)(CSStr, Int32, Int32, Uint8, Uint8, Uint8, Uint8, bool) >
(_SC("CreateEx"), &Textdraw_CreateEx)
.StaticOverload< Object & (*)(CSStr, Int32, Int32, Uint8, Uint8, Uint8, Uint8, bool, Int32, Object &) >
(_SC("CreateEx"), &Textdraw_CreateEx)
.StaticOverload< Object & (*)(Int32, CSStr, Int32, Int32, Uint8, Uint8, Uint8, Uint8, bool) >
(_SC("CreateEx"), &Textdraw_CreateEx)
.StaticOverload< Object & (*)(Int32, CSStr, Int32, Int32, Uint8, Uint8, Uint8, Uint8, bool, Int32, Object &) >
(_SC("CreateEx"), &Textdraw_CreateEx)
.StaticOverload< Object & (*)(CSStr, const Vector2i &, const Color4 &, bool) >
(_SC("Create"), &Textdraw_Create)
.StaticOverload< Object & (*)(CSStr, const Vector2i &, const Color4 &, bool, Int32, Object &) >
(_SC("Create"), &Textdraw_Create)
.StaticOverload< Object & (*)(Int32, CSStr, const Vector2i &, const Color4 &, bool) >
(_SC("Create"), &Textdraw_Create)
.StaticOverload< Object & (*)(Int32, CSStr, const Vector2i &, const Color4 &, bool, Int32, Object &) >
(_SC("Create"), &Textdraw_Create)
);
RootTable(vm)
.Overload< Object & (*)(CSStr, Int32, Int32, Uint8, Uint8, Uint8, Uint8, bool) >
(_SC("CreateTextdrawEx"), &CreateTextdrawEx)
.Overload< Object & (*)(CSStr, Int32, Int32, Uint8, Uint8, Uint8, Uint8, bool, Int32, Object &) >
(_SC("CreateTextdrawEx"), &CreateTextdrawEx)
.Overload< Object & (*)(Int32, CSStr, Int32, Int32, Uint8, Uint8, Uint8, Uint8, bool) >
(_SC("CreateTextdrawEx"), &CreateTextdrawEx)
.Overload< Object & (*)(Int32, CSStr, Int32, Int32, Uint8, Uint8, Uint8, Uint8, bool, Int32, Object &) >
(_SC("CreateTextdrawEx"), &CreateTextdrawEx)
.Overload< Object & (*)(CSStr, const Vector2i &, const Color4 &, bool) >
(_SC("CreateTextdraw"), &CreateTextdraw)
.Overload< Object & (*)(CSStr, const Vector2i &, const Color4 &, bool, Int32, Object &) >
(_SC("CreateTextdraw"), &CreateTextdraw)
.Overload< Object & (*)(Int32, CSStr, const Vector2i &, const Color4 &, bool) >
(_SC("CreateTextdraw"), &CreateTextdraw)
.Overload< Object & (*)(Int32, CSStr, const Vector2i &, const Color4 &, bool, Int32, Object &) >
(_SC("CreateTextdraw"), &CreateTextdraw);
}
} // Namespace:: SqMod
} // Namespace:: SqMod

View File

@ -8,7 +8,7 @@
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Manages Textdraw instances.
* Manages a single textdraw entity.
*/
class CTextdraw
{
@ -17,20 +17,19 @@ class CTextdraw
private:
/* --------------------------------------------------------------------------------------------
* Cached identifiers for fast integer to string conversion.
*/
static SQChar s_StrID[SQMOD_TEXTDRAW_POOL][8];
/* --------------------------------------------------------------------------------------------
* Identifier of the managed entity.
*/
Int32 m_ID;
/* --------------------------------------------------------------------------------------------
* User tag and data associated with this instance.
* User tag associated with this instance.
*/
String m_Tag;
/* --------------------------------------------------------------------------------------------
* User data associated with this instance.
*/
Object m_Data;
/* --------------------------------------------------------------------------------------------
@ -38,35 +37,45 @@ private:
*/
CTextdraw(Int32 id);
public:
/* --------------------------------------------------------------------------------------------
* Maximum possible number that could represent an identifier for this entity type.
*/
static const Int32 Max;
/* --------------------------------------------------------------------------------------------
* Copy constructor. (disabled)
*/
CTextdraw(const CTextdraw &);
CTextdraw(const CTextdraw &) = delete;
/* --------------------------------------------------------------------------------------------
* Copy assignment operator. (disabled)
* Move constructor. (disabled)
*/
CTextdraw & operator = (const CTextdraw &);
public:
// --------------------------------------------------------------------------------------------
static const Int32 Max;
CTextdraw(CTextdraw &&) = delete;
/* --------------------------------------------------------------------------------------------
* Destructor.
*/
~CTextdraw();
/* --------------------------------------------------------------------------------------------
* Copy assignment operator. (disabled)
*/
CTextdraw & operator = (const CTextdraw &) = delete;
/* --------------------------------------------------------------------------------------------
* Move assignment operator. (disabled)
*/
CTextdraw & operator = (CTextdraw &&) = delete;
/* --------------------------------------------------------------------------------------------
* See whether this instance manages a valid entity.
*/
bool Validate() const
void Validate() const
{
if (VALID_ENTITY(m_ID))
return true;
SqThrow("Invalid textdraw reference [%s]", m_Tag.c_str());
return false;
if (INVALID_ENTITY(m_ID))
SqThrowF("Invalid textdraw reference [%s]", m_Tag.c_str());
}
/* --------------------------------------------------------------------------------------------
@ -77,27 +86,33 @@ public:
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
CSStr ToString() const;
const String & ToString() const;
/* --------------------------------------------------------------------------------------------
* Used by the script engine to retrieve the name from instances of this type.
*/
static SQInteger Typename(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Retrieve the identifier of the entity managed by this instance.
*/
Int32 GetID() const { return m_ID; }
/* --------------------------------------------------------------------------------------------
* Retrieve the maximum possible identifier to an entity of this type.
*/
Int32 GetMaxID() const { return SQMOD_TEXTDRAW_POOL; }
Int32 GetID() const
{
return m_ID;
}
/* --------------------------------------------------------------------------------------------
* Check whether this instance manages a valid entity.
*/
bool IsActive() const { return VALID_ENTITY(m_ID); }
bool IsActive() const
{
return VALID_ENTITY(m_ID);
}
/* --------------------------------------------------------------------------------------------
* Retrieve the associated user tag.
*/
CSStr GetTag() const;
const String & GetTag() const;
/* --------------------------------------------------------------------------------------------
* Modify the associated user tag.
@ -114,32 +129,116 @@ public:
*/
void SetData(Object & data);
// --------------------------------------------------------------------------------------------
/* --------------------------------------------------------------------------------------------
* Destroy the managed textdraw entity.
*/
bool Destroy()
{
return Destroy(0, NullObject());
}
/* --------------------------------------------------------------------------------------------
* Destroy the managed textdraw entity.
*/
bool Destroy(Int32 header)
{
return Destroy(header, NullObject());
}
/* --------------------------------------------------------------------------------------------
* Destroy the managed textdraw entity.
*/
bool Destroy(Int32 header, Object & payload);
bool Destroy() { return Destroy(0, NullObject()); }
bool Destroy(Int32 header) { return Destroy(header, NullObject()); }
// --------------------------------------------------------------------------------------------
bool BindEvent(Int32 evid, Object & env, Function & func) const;
/* --------------------------------------------------------------------------------------------
* Bind to an event supported by this entity type.
*/
void BindEvent(Int32 evid, Object & env, Function & func) const;
// --------------------------------------------------------------------------------------------
/* --------------------------------------------------------------------------------------------
* Show the managed textdraw entity to all players on the server.
*/
void ShowAll() const;
/* --------------------------------------------------------------------------------------------
* Show the managed textdraw entity to the specified player entity.
*/
void ShowFor(CPlayer & player) const;
/* --------------------------------------------------------------------------------------------
* Show the managed textdraw entity to all players in the specified range.
*/
void ShowRange(Int32 first, Int32 last) const;
/* --------------------------------------------------------------------------------------------
* Hide the managed textdraw entity from all players on the server.
*/
void HideAll() const;
/* --------------------------------------------------------------------------------------------
* Hide the managed textdraw entity from the specified player entity.
*/
void HideFor(CPlayer & player) const;
/* --------------------------------------------------------------------------------------------
* Hide the managed textdraw entity from all players in the specified range.
*/
void HideRange(Int32 first, Int32 last) const;
/* --------------------------------------------------------------------------------------------
* Set the position of the managed textdraw entity for all players on the server.
*/
void SetPositionAll(const Vector2i & pos) const;
/* --------------------------------------------------------------------------------------------
* Set the position of the managed textdraw entity for all players on the server.
*/
void SetPositionAllEx(Int32 x, Int32 y) const;
/* --------------------------------------------------------------------------------------------
* Set the position of the managed textdraw entity for the specified player entity.
*/
void SetPositionFor(CPlayer & player, const Vector2i & pos) const;
/* --------------------------------------------------------------------------------------------
* Set the position of the managed textdraw entity for the specified player entity.
*/
void SetPositionForEx(CPlayer & player, Int32 x, Int32 y) const;
/* --------------------------------------------------------------------------------------------
* Set the position of the managed textdraw entity for all players in the specified range.
*/
void SetPositionRange(Int32 first, Int32 last, const Vector2i & pos) const;
/* --------------------------------------------------------------------------------------------
* Set the center of the managed textdraw entity for all players on the server.
*/
void SetColorAll(const Color4 & col) const;
/* --------------------------------------------------------------------------------------------
* Set the color of the managed textdraw entity for all players on the server.
*/
void SetColorAllEx(Uint8 r, Uint8 g, Uint8 b, Uint8 a) const;
/* --------------------------------------------------------------------------------------------
* Set the color of the managed textdraw entity for the specified player entity.
*/
void SetColorFor(CPlayer & player, const Color4 & col) const;
/* --------------------------------------------------------------------------------------------
* Set the color of the managed textdraw entity for the specified player entity.
*/
void SetColorForEx(CPlayer & player, Uint8 r, Uint8 g, Uint8 b, Uint8 a) const;
/* --------------------------------------------------------------------------------------------
* Set the color of the managed textdraw entity for all players in the specified range.
*/
void SetColorRange(Int32 first, Int32 last, const Color4 & col) const;
CSStr GetText() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the text string used by the managed textdraw entity.
*/
const String & GetText() const;
};
} // Namespace:: SqMod

File diff suppressed because it is too large Load Diff

View File

@ -8,7 +8,7 @@
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Manages Vehicle instances.
* Manages a single vehicle entity.
*/
class CVehicle
{
@ -22,20 +22,19 @@ private:
static Vector4 s_Vector4;
static Quaternion s_Quaternion;
/* --------------------------------------------------------------------------------------------
* Cached identifiers for fast integer to string conversion.
*/
static SQChar s_StrID[SQMOD_VEHICLE_POOL][8];
/* --------------------------------------------------------------------------------------------
* Identifier of the managed entity.
*/
Int32 m_ID;
/* --------------------------------------------------------------------------------------------
* User tag and data associated with this instance.
* User tag associated with this instance.
*/
String m_Tag;
/* --------------------------------------------------------------------------------------------
* User data associated with this instance.
*/
Object m_Data;
/* --------------------------------------------------------------------------------------------
@ -43,35 +42,45 @@ private:
*/
CVehicle(Int32 id);
public:
/* --------------------------------------------------------------------------------------------
* Maximum possible number that could represent an identifier for this entity type.
*/
static const Int32 Max;
/* --------------------------------------------------------------------------------------------
* Copy constructor. (disabled)
*/
CVehicle(const CVehicle &);
CVehicle(const CVehicle &) = delete;
/* --------------------------------------------------------------------------------------------
* Copy assignment operator. (disabled)
* Move constructor. (disabled)
*/
CVehicle & operator = (const CVehicle &);
public:
// --------------------------------------------------------------------------------------------
static const Int32 Max;
CVehicle(CVehicle &&) = delete;
/* --------------------------------------------------------------------------------------------
* Destructor.
*/
~CVehicle();
/* --------------------------------------------------------------------------------------------
* Copy assignment operator. (disabled)
*/
CVehicle & operator = (const CVehicle &) = delete;
/* --------------------------------------------------------------------------------------------
* Move assignment operator. (disabled)
*/
CVehicle & operator = (CVehicle &&) = delete;
/* --------------------------------------------------------------------------------------------
* See whether this instance manages a valid entity.
*/
bool Validate() const
void Validate() const
{
if (VALID_ENTITY(m_ID))
return true;
SqThrow("Invalid vehicle reference [%s]", m_Tag.c_str());
return false;
if (INVALID_ENTITY(m_ID))
SqThrowF("Invalid vehicle reference [%s]", m_Tag.c_str());
}
/* --------------------------------------------------------------------------------------------
@ -82,27 +91,33 @@ public:
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
CSStr ToString() const;
const String & ToString() const;
/* --------------------------------------------------------------------------------------------
* Used by the script engine to retrieve the name from instances of this type.
*/
static SQInteger Typename(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Retrieve the identifier of the entity managed by this instance.
*/
Int32 GetID() const { return m_ID; }
/* --------------------------------------------------------------------------------------------
* Retrieve the maximum possible identifier to an entity of this type.
*/
Int32 GetMaxID() const { return SQMOD_VEHICLE_POOL; }
Int32 GetID() const
{
return m_ID;
}
/* --------------------------------------------------------------------------------------------
* Check whether this instance manages a valid entity.
*/
bool IsActive() const { return VALID_ENTITY(m_ID); }
bool IsActive() const
{
return VALID_ENTITY(m_ID);
}
/* --------------------------------------------------------------------------------------------
* Retrieve the associated user tag.
*/
CSStr GetTag() const;
const String & GetTag() const;
/* --------------------------------------------------------------------------------------------
* Modify the associated user tag.
@ -119,126 +134,560 @@ public:
*/
void SetData(Object & data);
// --------------------------------------------------------------------------------------------
/* --------------------------------------------------------------------------------------------
* Destroy the managed vehicle entity.
*/
bool Destroy()
{
return Destroy(0, NullObject());
}
/* --------------------------------------------------------------------------------------------
* Destroy the managed vehicle entity.
*/
bool Destroy(Int32 header)
{
return Destroy(header, NullObject());
}
/* --------------------------------------------------------------------------------------------
* Destroy the managed vehicle entity.
*/
bool Destroy(Int32 header, Object & payload);
bool Destroy() { return Destroy(0, NullObject()); }
bool Destroy(Int32 header) { return Destroy(header, NullObject()); }
// --------------------------------------------------------------------------------------------
bool BindEvent(Int32 evid, Object & env, Function & func) const;
/* --------------------------------------------------------------------------------------------
* Bind to an event supported by this entity type.
*/
void BindEvent(Int32 evid, Object & env, Function & func) const;
// --------------------------------------------------------------------------------------------
/* --------------------------------------------------------------------------------------------
* See if the managed vehicle entity is streamed for the specified player.
*/
bool IsStreamedFor(CPlayer & player) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the synchronization source of the managed vehicle entity.
*/
Int32 GetSyncSource() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the synchronization type of the managed vehicle entity.
*/
Int32 GetSyncType() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the world in which the managed vehicle entity exists.
*/
Int32 GetWorld() const;
/* --------------------------------------------------------------------------------------------
* Modify the world in which the managed vehicle entity exists.
*/
void SetWorld(Int32 world) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the vehicle model of the managed vehicle entity.
*/
Int32 GetModel() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the slot occupant from the managed vehicle entity.
*/
Object & GetOccupant(Int32 slot) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the slot occupant identifier from the managed vehicle entity.
*/
Int32 GetOccupantID(Int32 slot) const;
/* --------------------------------------------------------------------------------------------
* Respawn the managed vehicle entity.
*/
void Respawn() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the immunity flags of the managed vehicle entity.
*/
Int32 GetImmunity() const;
/* --------------------------------------------------------------------------------------------
* Modify the immunity flags of the managed vehicle entity.
*/
void SetImmunity(Int32 flags) const;
/* --------------------------------------------------------------------------------------------
* See whether the managed vehicle entity is wrecked.
*/
bool IsWrecked() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the position of the managed vehicle entity.
*/
const Vector3 & GetPosition() const;
/* --------------------------------------------------------------------------------------------
* Modify the position of the managed vehicle entity.
*/
void SetPosition(const Vector3 & pos) const;
/* --------------------------------------------------------------------------------------------
* Modify the position of the managed vehicle entity.
*/
void SetPositionEx(const Vector3 & pos, bool empty) const;
/* --------------------------------------------------------------------------------------------
* Modify the position of the managed vehicle entity.
*/
void SetPositionEx(Float32 x, Float32 y, Float32 z) const;
/* --------------------------------------------------------------------------------------------
* Modify the position of the managed vehicle entity.
*/
void SetPositionEx(Float32 x, Float32 y, Float32 z, bool empty) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the rotation of the managed vehicle entity.
*/
const Quaternion & GetRotation() const;
/* --------------------------------------------------------------------------------------------
* Modify the rotation of the managed vehicle entity.
*/
void SetRotation(const Quaternion & rot) const;
/* --------------------------------------------------------------------------------------------
* Modify the rotation of the managed vehicle entity.
*/
void SetRotationEx(Float32 x, Float32 y, Float32 z, Float32 w) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the euler rotation of the managed vehicle entity.
*/
const Vector3 & GetRotationEuler() const;
/* --------------------------------------------------------------------------------------------
* Modify the euler rotation of the managed vehicle entity.
*/
void SetRotationEuler(const Vector3 & rot) const;
/* --------------------------------------------------------------------------------------------
* Modify the euler rotation of the managed vehicle entity.
*/
void SetRotationEulerEx(Float32 x, Float32 y, Float32 z) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the speed of the managed vehicle entity.
*/
const Vector3 & GetSpeed() const;
/* --------------------------------------------------------------------------------------------
* Modify the speed of the managed vehicle entity.
*/
void SetSpeed(const Vector3 & vel) const;
/* --------------------------------------------------------------------------------------------
* Modify the speed of the managed vehicle entity.
*/
void SetSpeedEx(Float32 x, Float32 y, Float32 z) const;
/* --------------------------------------------------------------------------------------------
* Modify the speed of the managed vehicle entity.
*/
void AddSpeed(const Vector3 & vel) const;
/* --------------------------------------------------------------------------------------------
* Modify the speed of the managed vehicle entity.
*/
void AddSpeedEx(Float32 x, Float32 y, Float32 z) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the relative speed of the managed vehicle entity.
*/
const Vector3 & GetRelSpeed() const;
/* --------------------------------------------------------------------------------------------
* Modify the relative speed of the managed vehicle entity.
*/
void SetRelSpeed(const Vector3 & vel) const;
/* --------------------------------------------------------------------------------------------
* Modify the relative speed of the managed vehicle entity.
*/
void SetRelSpeedEx(Float32 x, Float32 y, Float32 z) const;
/* --------------------------------------------------------------------------------------------
* Modify the relative speed of the managed vehicle entity.
*/
void AddRelSpeed(const Vector3 & vel) const;
/* --------------------------------------------------------------------------------------------
* Modify the relative speed of the managed vehicle entity.
*/
void AddRelSpeedEx(Float32 x, Float32 y, Float32 z) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the turn speed of the managed vehicle entity.
*/
const Vector3 & GetTurnSpeed() const;
/* --------------------------------------------------------------------------------------------
* Modify the turn speed of the managed vehicle entity.
*/
void SetTurnSpeed(const Vector3 & vel) const;
/* --------------------------------------------------------------------------------------------
* Modify the turn speed of the managed vehicle entity.
*/
void SetTurnSpeedEx(Float32 x, Float32 y, Float32 z) const;
/* --------------------------------------------------------------------------------------------
* Modify the turn speed of the managed vehicle entity.
*/
void AddTurnSpeed(const Vector3 & vel) const;
/* --------------------------------------------------------------------------------------------
* Modify the turn speed of the managed vehicle entity.
*/
void AddTurnSpeedEx(Float32 x, Float32 y, Float32 z) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the relative turn speed of the managed vehicle entity.
*/
const Vector3 & GetRelTurnSpeed() const;
/* --------------------------------------------------------------------------------------------
* Modify the relative turn speed of the managed vehicle entity.
*/
void SetRelTurnSpeed(const Vector3 & vel) const;
/* --------------------------------------------------------------------------------------------
* Modify the relative turn speed of the managed vehicle entity.
*/
void SetRelTurnSpeedEx(Float32 x, Float32 y, Float32 z) const;
/* --------------------------------------------------------------------------------------------
* Modify the relative turn speed of the managed vehicle entity.
*/
void AddRelTurnSpeed(const Vector3 & vel) const;
/* --------------------------------------------------------------------------------------------
* Modify the relative turn speed of the managed vehicle entity.
*/
void AddRelTurnSpeedEx(Float32 x, Float32 y, Float32 z) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the spawn position of the managed vehicle entity.
*/
const Vector4 & GetSpawnPosition() const;
/* --------------------------------------------------------------------------------------------
* Modify the spawn position of the managed vehicle entity.
*/
void SetSpawnPosition(const Vector4 & pos) const;
/* --------------------------------------------------------------------------------------------
* Modify the spawn position of the managed vehicle entity.
*/
void SetSpawnPositionEx(Float32 x, Float32 y, Float32 z, Float32 w) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the spawn rotation of the managed vehicle entity.
*/
const Quaternion & GetSpawnRotation() const;
/* --------------------------------------------------------------------------------------------
* Modify the spawn rotation of the managed vehicle entity.
*/
void SetSpawnRotation(const Quaternion & rot) const;
/* --------------------------------------------------------------------------------------------
* Modify the spawn rotation of the managed vehicle entity.
*/
void SetSpawnRotationEx(Float32 x, Float32 y, Float32 z, Float32 w) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the euler spawn rotation of the managed vehicle entity.
*/
const Vector3 & GetSpawnRotationEuler() const;
/* --------------------------------------------------------------------------------------------
* Modify the euler spawn rotation of the managed vehicle entity.
*/
void SetSpawnRotationEuler(const Vector3 & rot) const;
/* --------------------------------------------------------------------------------------------
* Modify the euler spawn rotation of the managed vehicle entity.
*/
void SetSpawnRotationEulerEx(Float32 x, Float32 y, Float32 z) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the respawn timer of the managed vehicle entity.
*/
Uint32 GetRespawnTimer() const;
/* --------------------------------------------------------------------------------------------
* Modify the respawn timer of the managed vehicle entity.
*/
void SetRespawnTimer(Uint32 timer) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the health of the managed vehicle entity.
*/
Float32 GetHealth() const;
/* --------------------------------------------------------------------------------------------
* Modify the health of the managed vehicle entity.
*/
void SetHealth(Float32 amount) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the primary color of the managed vehicle entity.
*/
Int32 GetPrimaryColor() const;
/* --------------------------------------------------------------------------------------------
* Modify the primary color of the managed vehicle entity.
*/
void SetPrimaryColor(Int32 col) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the secondary color of the managed vehicle entity.
*/
Int32 GetSecondaryColor() const;
/* --------------------------------------------------------------------------------------------
* Modify the secondary color of the managed vehicle entity.
*/
void SetSecondaryColor(Int32 col) const;
/* --------------------------------------------------------------------------------------------
* Modify the primary and secondary colors of the managed vehicle entity.
*/
void SetColors(Int32 primary, Int32 secondary) const;
/* --------------------------------------------------------------------------------------------
* See whether the managed vehicle entity is locked.
*/
bool GetLocked() const;
/* --------------------------------------------------------------------------------------------
* Set whether the managed vehicle entity is locked.
*/
void SetLocked(bool toggle) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the part status of the managed vehicle entity.
*/
Int32 GetPartStatus(Int32 part) const;
/* --------------------------------------------------------------------------------------------
* Modify the part status of the managed vehicle entity.
*/
void SetPartStatus(Int32 part, Int32 status) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the tyre status of the managed vehicle entity.
*/
Int32 GetTyreStatus(Int32 tyre) const;
/* --------------------------------------------------------------------------------------------
* Modify the tyre status of the managed vehicle entity.
*/
void SetTyreStatus(Int32 tyre, Int32 status) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the damage data of the managed vehicle entity.
*/
Uint32 GetDamageData() const;
/* --------------------------------------------------------------------------------------------
* Modify the damage data of the managed vehicle entity.
*/
void SetDamageData(Uint32 data) const;
/* --------------------------------------------------------------------------------------------
* See whether the managed vehicle entity has alarm.
*/
bool GetAlarm() const;
/* --------------------------------------------------------------------------------------------
* Set whether the managed vehicle entity has alarm.
*/
void SetAlarm(bool toggle) const;
/* --------------------------------------------------------------------------------------------
* See whether the managed vehicle entity has lights.
*/
bool GetLights() const;
/* --------------------------------------------------------------------------------------------
* Set whether the managed vehicle entity has lights.
*/
void SetLights(bool toggle) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the radio of the managed vehicle entity.
*/
Int32 GetRadio() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the radio of the managed vehicle entity.
*/
void SetRadio(Int32 radio) const;
/* --------------------------------------------------------------------------------------------
* See whether the managed vehicle entity has radio locked.
*/
bool GetRadioLocked() const;
/* --------------------------------------------------------------------------------------------
* Set whether the managed vehicle entity has radio locked.
*/
void SetRadioLocked(bool toggle) const;
/* --------------------------------------------------------------------------------------------
* See whether the managed vehicle entity is in ghost state.
*/
bool GetGhostState() const;
/* --------------------------------------------------------------------------------------------
* Set whether the managed vehicle entity is in ghost state.
*/
void SetGhostState(bool toggle) const;
/* --------------------------------------------------------------------------------------------
* Reset all the handling rules for the managed vehicle entity.
*/
void ResetHandling() const;
/* --------------------------------------------------------------------------------------------
* Reset the specified handling rule for the managed vehicle entity.
*/
void ResetHandling(Int32 rule) const;
/* --------------------------------------------------------------------------------------------
* See whether the specified handling ruleexists in the managed vehicle entity.
*/
bool ExistsHandling(Int32 rule) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the handling data of the managed vehicle entity.
*/
Float32 GetHandlingData(Int32 rule) const;
/* --------------------------------------------------------------------------------------------
* Modify the handling data of the managed vehicle entity.
*/
void SetHandlingData(Int32 rule, Float32 data) const;
/* --------------------------------------------------------------------------------------------
* Embark the specified player entity into the managed vehicle entity.
*/
void Embark(CPlayer & player) const;
/* --------------------------------------------------------------------------------------------
* Embark the specified player entity into the managed vehicle entity.
*/
void Embark(CPlayer & player, Int32 slot, bool allocate, bool warp) const;
// --------------------------------------------------------------------------------------------
/* --------------------------------------------------------------------------------------------
* Retrieve the position on the x axis of the managed vehicle entity.
*/
Float32 GetPosX() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the position on the y axis of the managed vehicle entity.
*/
Float32 GetPosY() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the position on the z axis of the managed vehicle entity.
*/
Float32 GetPosZ() const;
/* --------------------------------------------------------------------------------------------
* Modify the position on the x axis of the managed vehicle entity.
*/
void SetPosX(Float32 x) const;
/* --------------------------------------------------------------------------------------------
* Modify the position on the y axis of the managed vehicle entity.
*/
void SetPosY(Float32 y) const;
/* --------------------------------------------------------------------------------------------
* Modify the position on the z axis of the managed vehicle entity.
*/
void SetPosZ(Float32 z) const;
// --------------------------------------------------------------------------------------------
/* --------------------------------------------------------------------------------------------
* Retrieve the rotation on the x axis of the managed vehicle entity.
*/
Float32 GetRotX() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the rotation on the y axis of the managed vehicle entity.
*/
Float32 GetRotY() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the rotation on the z axis of the managed vehicle entity.
*/
Float32 GetRotZ() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the rotation amount of the managed vehicle entity.
*/
Float32 GetRotW() const;
/* --------------------------------------------------------------------------------------------
* Modify the rotation on the x axis of the managed vehicle entity.
*/
void SetRotX(Float32 x) const;
/* --------------------------------------------------------------------------------------------
* Modify the rotation on the y axis of the managed vehicle entity.
*/
void SetRotY(Float32 y) const;
/* --------------------------------------------------------------------------------------------
* Modify the rotation on the z axis of the managed vehicle entity.
*/
void SetRotZ(Float32 z) const;
/* --------------------------------------------------------------------------------------------
* Modify the rotation amount of the managed vehicle entity.
*/
void SetRotW(Float32 w) const;
// --------------------------------------------------------------------------------------------
/* --------------------------------------------------------------------------------------------
* Retrieve the euler rotation on the x axis of the managed vehicle entity.
*/
Float32 GetERotX() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the euler rotation on the y axis of the managed vehicle entity.
*/
Float32 GetERotY() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the euler rotation on the z axis of the managed vehicle entity.
*/
Float32 GetERotZ() const;
/* --------------------------------------------------------------------------------------------
* Modify the euler rotation on the x axis of the managed vehicle entity.
*/
void SetERotX(Float32 x) const;
/* --------------------------------------------------------------------------------------------
* Modify the euler rotation on the y axis of the managed vehicle entity.
*/
void SetERotY(Float32 y) const;
/* --------------------------------------------------------------------------------------------
* Modify the euler rotation on the z axis of the managed vehicle entity.
*/
void SetERotZ(Float32 z) const;
};