From ab5c9c26868335812a012b6505c926a9a17f12a9 Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Thu, 29 Oct 2015 22:11:00 +0200 Subject: [PATCH] Untested implementation of the Pickup type. --- source/Entity/Pickup.cpp | 276 +++++++++++++++++++++++++++++++++++++-- source/Entity/Pickup.hpp | 93 ++++++++++++- 2 files changed, 358 insertions(+), 11 deletions(-) diff --git a/source/Entity/Pickup.cpp b/source/Entity/Pickup.cpp index 53cc1ebe..6d4d473c 100644 --- a/source/Entity/Pickup.cpp +++ b/source/Entity/Pickup.cpp @@ -1,28 +1,286 @@ #include "Entity/Pickup.hpp" +#include "Misc/Model.hpp" #include "Register.hpp" // ------------------------------------------------------------------------------------------------ namespace SqMod { // ------------------------------------------------------------------------------------------------ -bool Register_CPickup(HSQUIRRELVM vm) -{ - if (!Register_Reference< CPickup >(vm, _SC("BasePickup"))) - { - LogDbg("Unable to register the base class for type"); +CModel CPickup::s_Model; - return false; +// ------------------------------------------------------------------------------------------------ +Vector3 CPickup::s_Vector3; + +// ------------------------------------------------------------------------------------------------ +bool CPickup::IsStreamedFor(const Reference< CPlayer > & player) const noexcept +{ + if (VALID_ENTITY(m_ID) && player) + { + return _Func->IsPickupStreamedForPlayer(m_ID, player); + } + else if (!player) + { + LogWrn(_SC("Attempting to using an invalid argument: %d"), _SCI32(player)); + } + else + { + LogWrn(_SC("Attempting to using an invalid reference: %d"), m_ID); } - LogDbg("Beginning registration of type"); + return false; +} +// ------------------------------------------------------------------------------------------------ +const CModel & CPickup::GetModel() const noexcept +{ + // Clear any previous model + s_Model.SetID(SQMOD_UNKNOWN); + // Attempt to retrieve the model + if (VALID_ENTITY(m_ID)) + { + s_Model.SetID(_Func->PickupGetModel(m_ID)); + } + else + { + LogWrn(_SC("Attempting to using an invalid reference: %d"), m_ID); + } + // Return the model that could be retrieved + return s_Model; +} + +// ------------------------------------------------------------------------------------------------ +SQInt32 CPickup::GetModelID() const noexcept +{ + if (VALID_ENTITY(m_ID)) + { + return _Func->PickupGetModel(m_ID); + } + else + { + LogWrn(_SC("Attempting to using an invalid reference: %d"), m_ID); + } + + return SQMOD_UNKNOWN; +} + +// ------------------------------------------------------------------------------------------------ +SQInt32 CPickup::GetWorld() const noexcept +{ + if (VALID_ENTITY(m_ID)) + { + return _Func->GetPickupWorld(m_ID); + } + else + { + LogWrn(_SC("Attempting to using an invalid reference: %d"), m_ID); + } + + return SQMOD_UNKNOWN; +} + +// ------------------------------------------------------------------------------------------------ +void CPickup::SetWorld(SQInt32 world) const noexcept +{ + if (VALID_ENTITY(m_ID)) + { + _Func->SetPickupWorld(m_ID, world); + } + else + { + LogWrn(_SC("Attempting to using an invalid reference: %d"), m_ID); + } +} + +// ------------------------------------------------------------------------------------------------ +SQInt32 CPickup::GetAlpha() const noexcept +{ + if (VALID_ENTITY(m_ID)) + { + return _Func->PickupGetAlpha(m_ID); + } + else + { + LogWrn(_SC("Attempting to using an invalid reference: %d"), m_ID); + } + + return SQMOD_UNKNOWN; +} + +// ------------------------------------------------------------------------------------------------ +void CPickup::SetAlpha(SQInt32 alpha) const noexcept +{ + if (VALID_ENTITY(m_ID)) + { + _Func->PickupSetAlpha(m_ID, alpha); + } + else + { + LogWrn(_SC("Attempting to using an invalid reference: %d"), m_ID); + } +} + +// ------------------------------------------------------------------------------------------------ +bool CPickup::GetAutomatic() const noexcept +{ + if (VALID_ENTITY(m_ID)) + { + return _Func->PickupIsAutomatic(m_ID); + } + else + { + LogWrn(_SC("Attempting to using an invalid argument: %d"), m_ID); + } + + return false; +} + +// ------------------------------------------------------------------------------------------------ +void CPickup::SetAutomatic(bool toggle) const noexcept +{ + if (VALID_ENTITY(m_ID)) + { + _Func->PickupSetAutomatic(m_ID, toggle); + } + else + { + LogWrn(_SC("Attempting to using an invalid argument: %d"), m_ID); + } +} + +// ------------------------------------------------------------------------------------------------ +SQInt32 CPickup::GetAutoTimer() const noexcept +{ + if (VALID_ENTITY(m_ID)) + { + return _Func->GetPickupAutoTimer(m_ID); + } + else + { + LogWrn(_SC("Attempting to using an invalid reference: %d"), m_ID); + } + + return SQMOD_UNKNOWN; +} + +// ------------------------------------------------------------------------------------------------ +void CPickup::SetAutoTimer(SQInt32 timer) const noexcept +{ + if (VALID_ENTITY(m_ID)) + { + _Func->SetPickupAutoTimer(m_ID, timer); + } + else + { + LogWrn(_SC("Attempting to using an invalid reference: %d"), m_ID); + } +} + +// ------------------------------------------------------------------------------------------------ +void CPickup::Refresh() const noexcept +{ + if (VALID_ENTITY(m_ID)) + { + _Func->PickupRefresh(m_ID); + } + else + { + LogWrn(_SC("Attempting to using an invalid reference: %d"), m_ID); + } +} + +// ------------------------------------------------------------------------------------------------ +const Vector3 & CPickup::GetPosition() noexcept +{ + // Clear any previous position + s_Vector3.Clear(); + // Attempt to retrieve the position + if (VALID_ENTITY(m_ID)) + { + _Func->PickupGetPos(m_ID, &s_Vector3.x, &s_Vector3.y, &s_Vector3.z); + } + else + { + LogWrn(_SC("Attempting to using an invalid reference: %d"), m_ID); + } + // Return the position that could be retrieved + return s_Vector3; +} + +// ------------------------------------------------------------------------------------------------ +void CPickup::SetPosition(const Vector3 & pos) const noexcept +{ + if (VALID_ENTITY(m_ID)) + { + _Func->PickupSetPos(m_ID, pos.x, pos.y, pos.z); + } + else + { + LogWrn(_SC("Attempting to using an invalid reference: %d"), m_ID); + } +} + +// ------------------------------------------------------------------------------------------------ +void CPickup::SetPositionEx(SQFloat x, SQFloat y, SQFloat z) const noexcept +{ + if (VALID_ENTITY(m_ID)) + { + _Func->PickupSetPos(m_ID, x, y, z); + } + else + { + LogWrn(_SC("Attempting to using an invalid reference: %d"), m_ID); + } +} + +// ------------------------------------------------------------------------------------------------ +SQInt32 CPickup::GetQuantity() const noexcept +{ + if (VALID_ENTITY(m_ID)) + { + return _Func->PickupGetQuantity(m_ID); + } + else + { + LogWrn(_SC("Attempting to using an invalid reference: %d"), m_ID); + } + + return SQMOD_UNKNOWN; +} + +// ================================================================================================ +bool Register_CPickup(HSQUIRRELVM vm) +{ + // Attempt to register the base reference type before the actual implementation + if (!Register_Reference< CPickup >(vm, _SC("BasePickup"))) + { + LogFtl("Unable to register the base class for type"); + // Registration failed + return false; + } + // Output debugging information + LogDbg("Beginning registration of type"); + // Attempt to register the actual reference that implements all of the entity functionality Sqrat::RootTable(vm).Bind(_SC("CPickup"), Sqrat::DerivedClass< CPickup, Reference< CPickup > >(vm, _SC("CPickup")) + /* Constructors */ .Ctor() .Ctor< SQInt32 >() + /* Properties */ + .Prop(_SC("model"), &CPickup::GetModel) + .Prop(_SC("model_id"), &CPickup::GetModelID) + .Prop(_SC("world"), &CPickup::GetWorld, &CPickup::SetWorld) + .Prop(_SC("alpha"), &CPickup::GetAlpha, &CPickup::SetAlpha) + .Prop(_SC("automatic"), &CPickup::GetAutomatic, &CPickup::SetAutomatic) + .Prop(_SC("auto_timer"), &CPickup::GetAutoTimer, &CPickup::SetAutoTimer) + .Prop(_SC("position"), &CPickup::GetPosition, &CPickup::SetPosition) + .Prop(_SC("quantity"), &CPickup::GetQuantity) + /* Functions */ + .Func(_SC("streamed_for"), &CPickup::IsStreamedFor) + .Func(_SC("refresh"), &CPickup::Refresh) + .Func(_SC("set_position"), &CPickup::SetPositionEx) ); - + // Output debugging information LogDbg("Registration of type was successful"); - + // Registration succeeded return true; } diff --git a/source/Entity/Pickup.hpp b/source/Entity/Pickup.hpp index c9d73f27..bd14ebe8 100644 --- a/source/Entity/Pickup.hpp +++ b/source/Entity/Pickup.hpp @@ -8,13 +8,102 @@ namespace SqMod { /* ------------------------------------------------------------------------------------------------ - * ... + * Class responsible for managing the referenced pickup instance. */ class CPickup : public Reference< CPickup > { -public: // -------------------------------------------------------------------------------------------- + static CModel s_Model; + + // -------------------------------------------------------------------------------------------- + static Vector3 s_Vector3; + +public: + + /* -------------------------------------------------------------------------------------------- + * Import the constructors, destructors and assignment operators from the base class. + */ using RefType::Reference; + + /* -------------------------------------------------------------------------------------------- + * See if the referenced pickup instance is streamed for the specified player. + */ + bool IsStreamedFor(const Reference< CPlayer > & player) const noexcept; + + /* -------------------------------------------------------------------------------------------- + * Retrieve the model of the referenced pickup instance. + */ + const CModel & GetModel() const noexcept; + + /* -------------------------------------------------------------------------------------------- + * Retrieve the model identifier of the referenced pickup instance. + */ + SQInt32 GetModelID() const noexcept; + + /* -------------------------------------------------------------------------------------------- + * Retrieve the world in which the referenced pickup instance exists. + */ + SQInt32 GetWorld() const noexcept; + + /* -------------------------------------------------------------------------------------------- + * Change the world in which the referenced pickup instance exists. + */ + void SetWorld(SQInt32 world) const noexcept; + + /* -------------------------------------------------------------------------------------------- + * Retrieve the alpha of the referenced pickup instance. + */ + SQInt32 GetAlpha() const noexcept; + + /* -------------------------------------------------------------------------------------------- + * Change the alpha of the referenced pickup instance. + */ + void SetAlpha(SQInt32 alpha) const noexcept; + + /* -------------------------------------------------------------------------------------------- + * See whether the referenced pickup instance is automatic. + */ + bool GetAutomatic() const noexcept; + + /* -------------------------------------------------------------------------------------------- + * Set whether the referenced pickup instance is automatic. + */ + void SetAutomatic(bool toggle) const noexcept; + + /* -------------------------------------------------------------------------------------------- + * Retrieve the automatic timer of the referenced pickup instance. + */ + SQInt32 GetAutoTimer() const noexcept; + + /* -------------------------------------------------------------------------------------------- + * Change the automatic timer of the referenced pickup instance. + */ + void SetAutoTimer(SQInt32 timer) const noexcept; + + /* -------------------------------------------------------------------------------------------- + * Refresh the referenced pickup instance. + */ + void Refresh() const noexcept; + + /* -------------------------------------------------------------------------------------------- + * Retrieve the position of the referenced pickup instance. + */ + const Vector3 & GetPosition() noexcept; + + /* -------------------------------------------------------------------------------------------- + * Change the position of the referenced pickup instance. + */ + void SetPosition(const Vector3 & pos) const noexcept; + + /* -------------------------------------------------------------------------------------------- + * Change the position of the referenced pickup instance. + */ + void SetPositionEx(SQFloat x, SQFloat y, SQFloat z) const noexcept; + + /* -------------------------------------------------------------------------------------------- + * Retrieve the quantity of the referenced pickup instance. + */ + SQInt32 GetQuantity() const noexcept; }; } // Namespace:: SqMod