diff --git a/source/Misc/Automobile.cpp b/source/Misc/Automobile.cpp index 51571c0e..3f53084d 100644 --- a/source/Misc/Automobile.cpp +++ b/source/Misc/Automobile.cpp @@ -13,27 +13,29 @@ const CAutomobile CAutomobile::NIL; // ------------------------------------------------------------------------------------------------ CAutomobile::CAutomobile() noexcept - : m_ID(SQMOD_UNKNOWN), m_Name() + : m_ID(SQMOD_UNKNOWN) { } CAutomobile::CAutomobile(SQInt32 id) noexcept - : m_ID(VALID_ENTITYGETEX(id, Max)), m_Name(GetAutomobileName(id)) + : m_ID(VALID_ENTITYGETEX(id, Max)) { } CAutomobile::CAutomobile(const SQChar * name, SQInt32 id) noexcept - : CAutomobile(IsAutomobileValid(GetAutomobileID(name)) ? GetAutomobileID(name) : id) + : m_ID(GetAutomobileID(name)) { - + if (VALID_ENTITYEX(m_ID, Max)) + { + m_ID = id; + } } // ------------------------------------------------------------------------------------------------ CAutomobile::CAutomobile(const CAutomobile & a) noexcept : m_ID(a.m_ID) - , m_Name(a.m_Name) , m_Tag(a.m_Tag) , m_Data(a.m_Data) { @@ -42,7 +44,6 @@ CAutomobile::CAutomobile(const CAutomobile & a) noexcept CAutomobile::CAutomobile(CAutomobile && a) noexcept : m_ID(a.m_ID) - , m_Name(a.m_Name) , m_Tag(a.m_Tag) , m_Data(a.m_Data) { @@ -59,7 +60,6 @@ CAutomobile::~CAutomobile() CAutomobile & CAutomobile::operator = (const CAutomobile & a) noexcept { m_ID = a.m_ID; - m_Name = a.m_Name; m_Tag = a.m_Tag; m_Data = a.m_Data; @@ -69,7 +69,6 @@ CAutomobile & CAutomobile::operator = (const CAutomobile & a) noexcept CAutomobile & CAutomobile::operator = (CAutomobile && a) noexcept { m_ID = a.m_ID; - m_Name = a.m_Name; m_Tag = a.m_Tag; m_Data = a.m_Data; @@ -79,11 +78,7 @@ CAutomobile & CAutomobile::operator = (CAutomobile && a) noexcept // ------------------------------------------------------------------------------------------------ CAutomobile & CAutomobile::operator = (SQInt32 id) noexcept { - if (m_ID != id) - { - m_Name = GetAutomobileName(id); - m_ID = id; - } + m_ID = VALID_ENTITYGETEX(id, Max); return *this; } @@ -122,13 +117,24 @@ bool CAutomobile::operator >= (const CAutomobile & a) const noexcept // ------------------------------------------------------------------------------------------------ SQInteger CAutomobile::Cmp(const CAutomobile & a) const noexcept { - return m_ID == a.m_ID ? 0 : (m_ID > a.m_ID ? 1 : -1); + if (m_ID == a.m_ID) + { + return 0; + } + else if (m_ID > a.m_ID) + { + return 1; + } + else + { + return -1; + } } // ------------------------------------------------------------------------------------------------ const SQChar * CAutomobile::ToString() const noexcept { - return m_Name.c_str(); + return GetAutomobileName(m_ID); } // ------------------------------------------------------------------------------------------------ @@ -139,21 +145,14 @@ SQInteger CAutomobile::GetID() const noexcept void CAutomobile::SetID(SQInt32 id) noexcept { - if (m_ID != id) - { - m_Name = GetAutomobileName(id); - m_ID = id; - } + m_ID = VALID_ENTITYGETEX(id, Max); } // ------------------------------------------------------------------------------------------------ CAutomobile & CAutomobile::SetnGet(SQInt32 id) noexcept { - if (m_ID != id) - { - m_Name = GetAutomobileName(id); - m_ID = id; - } + m_ID = VALID_ENTITYGETEX(id, Max); + return *this; } @@ -204,37 +203,44 @@ void CAutomobile::SetLocalData(SqObj & data) noexcept // ------------------------------------------------------------------------------------------------ bool CAutomobile::IsValid() const noexcept { - return (VALID_ENTITYEX(m_ID, SQMOD_VEHICLEID_CAP)); + return (VALID_ENTITYEX(m_ID, Max)); } // ------------------------------------------------------------------------------------------------ const SQChar * CAutomobile::GetName() const noexcept { - return m_Name.c_str(); + return GetAutomobileName(m_ID); } // ------------------------------------------------------------------------------------------------ -Reference< CVehicle > CAutomobile::Create(SQInt32 world, const Vector3 & pos, SQFloat angle, \ +void CAutomobile::SetName(const SQChar * name) noexcept +{ + m_ID = GetAutomobileID(name); + m_ID = VALID_ENTITYGETEX(m_ID, Max); +} + +// ------------------------------------------------------------------------------------------------ +Reference< CVehicle > CAutomobile::Create(SQInt32 world, const Vector3 & pos, SQFloat angle, SQInt32 header, SqObj & payload) const noexcept { return _Core->CreateVehicle(*this, world, pos, angle, SQMOD_UNKNOWN, SQMOD_UNKNOWN, header, payload); } -Reference< CVehicle > CAutomobile::Create(SQInt32 world, const Vector3 & pos, SQFloat angle, \ - SQInt32 primary, SQInt32 secondary, SQInt32 header, \ +Reference< CVehicle > CAutomobile::Create(SQInt32 world, const Vector3 & pos, SQFloat angle, + SQInt32 primary, SQInt32 secondary, SQInt32 header, SqObj & payload) const noexcept { return _Core->CreateVehicle(*this, world, pos, angle, primary, secondary, header, payload); } -Reference< CVehicle > CAutomobile::Create(SQInt32 world, SQFloat x, SQFloat y, SQFloat z, SQFloat angle, \ +Reference< CVehicle > CAutomobile::Create(SQInt32 world, SQFloat x, SQFloat y, SQFloat z, SQFloat angle, SQInt32 header, SqObj & payload) const noexcept { return _Core->CreateVehicle(*this, world, Vector3(x, y, z), angle, SQMOD_UNKNOWN, SQMOD_UNKNOWN, header, payload); } -Reference< CVehicle > CAutomobile::Create(SQInt32 world, SQFloat x, SQFloat y, SQFloat z, SQFloat angle, \ - SQInt32 primary, SQInt32 secondary, SQInt32 header, \ +Reference< CVehicle > CAutomobile::Create(SQInt32 world, SQFloat x, SQFloat y, SQFloat z, SQFloat angle, + SQInt32 primary, SQInt32 secondary, SQInt32 header, SqObj & payload) const noexcept { return _Core->CreateVehicle(*this, world, Vector3(x, y, z), angle, primary, secondary, header, payload); @@ -247,31 +253,32 @@ bool Register_CAutomobile(HSQUIRRELVM vm) LogDbg("Beginning registration of type"); // Attempt to register the specified type Sqrat::RootTable(vm).Bind(_SC("CAutomobile"), Sqrat::Class< CAutomobile >(vm, _SC("CAutomobile")) + /* Constructors */ .Ctor() .Ctor< SQInt32 >() .Ctor< const SQChar *, SQInt32 >() - + /* Metamethods */ .Func(_SC("_cmp"), &CAutomobile::Cmp) .Func(_SC("_tostring"), &CAutomobile::ToString) - + /* Properties */ .Prop(_SC("id"), &CAutomobile::GetID, &CAutomobile::SetID) .Prop(_SC("gtag"), &CAutomobile::GetGlobalTag, &CAutomobile::SetGlobalTag) .Prop(_SC("gdata"), &CAutomobile::GetGlobalData, &CAutomobile::SetGlobalData) .Prop(_SC("ltag"), &CAutomobile::GetLocalTag, &CAutomobile::SetLocalTag) .Prop(_SC("ldata"), &CAutomobile::GetLocalData, &CAutomobile::SetLocalData) .Prop(_SC("valid"), &CAutomobile::IsValid) - .Prop(_SC("name"), &CAutomobile::GetName) - + .Prop(_SC("name"), &CAutomobile::GetName, &CAutomobile::SetName) + /* Functions */ .Func(_SC("setng"), &CAutomobile::SetnGet) - - .Overload< Reference< CVehicle > (CAutomobile::*)(SQInt32, const Vector3 &, SQFloat, SQInt32, SqObj &) const > \ - (_SC("vehicle"), &CAutomobile::Create) - .Overload< Reference< CVehicle > (CAutomobile::*)(SQInt32, const Vector3 &, SQFloat, SQInt32, SQInt32, SQInt32, SqObj &) const > \ - (_SC("vehicle"), &CAutomobile::Create) - .Overload< Reference< CVehicle > (CAutomobile::*)(SQInt32, SQFloat, SQFloat, SQFloat, SQFloat, SQInt32, SqObj &) const > \ - (_SC("vehicle"), &CAutomobile::Create) - .Overload< Reference< CVehicle > (CAutomobile::*)(SQInt32, SQFloat, SQFloat, SQFloat, SQFloat, SQInt32, SQInt32, SQInt32, SqObj &) const > \ - (_SC("vehicle"), &CAutomobile::Create) + /* Overloads */ + .Overload< Reference< CVehicle > (CAutomobile::*)(SQInt32, const Vector3 &, SQFloat, SQInt32, SqObj &) const > + (_SC("vehicle"), &CAutomobile::Create) + .Overload< Reference< CVehicle > (CAutomobile::*)(SQInt32, const Vector3 &, SQFloat, SQInt32, SQInt32, SQInt32, SqObj &) const > + (_SC("vehicle"), &CAutomobile::Create) + .Overload< Reference< CVehicle > (CAutomobile::*)(SQInt32, SQFloat, SQFloat, SQFloat, SQFloat, SQInt32, SqObj &) const > + (_SC("vehicle"), &CAutomobile::Create) + .Overload< Reference< CVehicle > (CAutomobile::*)(SQInt32, SQFloat, SQFloat, SQFloat, SQFloat, SQInt32, SQInt32, SQInt32, SqObj &) const > + (_SC("vehicle"), &CAutomobile::Create) ); // Output debugging information LogDbg("Registration of type was successful"); diff --git a/source/Misc/Automobile.hpp b/source/Misc/Automobile.hpp index 08a08a2c..8afcd8f2 100644 --- a/source/Misc/Automobile.hpp +++ b/source/Misc/Automobile.hpp @@ -8,82 +8,239 @@ namespace SqMod { /* ------------------------------------------------------------------------------------------------ - * ... + * Class responsible for managing and interacting with vehicle models. */ class CAutomobile : public IdentifierStorage< CAutomobile, SQMOD_VEHICLEID_CAP > { public: - // -------------------------------------------------------------------------------------------- + + /* -------------------------------------------------------------------------------------------- + * Helper member for times when a null reference to an instance of this type is needed. + */ static const CAutomobile NIL; - // -------------------------------------------------------------------------------------------- + + /* -------------------------------------------------------------------------------------------- + * Default constructor. + */ CAutomobile() noexcept; + + /* -------------------------------------------------------------------------------------------- + * Construct an instance of this type and reference the model specified. + */ CAutomobile(SQInt32 id) noexcept; + + /* -------------------------------------------------------------------------------------------- + * Construct an instance of this type and reference the model extracted from the specified name. + */ CAutomobile(const SQChar * name, SQInt32 id) noexcept; - // -------------------------------------------------------------------------------------------- + + /* -------------------------------------------------------------------------------------------- + * Copy constructor. + */ CAutomobile(const CAutomobile & a) noexcept; + + /* -------------------------------------------------------------------------------------------- + * Move constructor. + */ CAutomobile(CAutomobile && a) noexcept; - // -------------------------------------------------------------------------------------------- + + /* -------------------------------------------------------------------------------------------- + * Destructor. + */ ~CAutomobile(); - // -------------------------------------------------------------------------------------------- + + /* -------------------------------------------------------------------------------------------- + * Copy assignment operator. + */ CAutomobile & operator = (const CAutomobile & a) noexcept; + + /* -------------------------------------------------------------------------------------------- + * Move assignment operator. + */ CAutomobile & operator = (CAutomobile && a) noexcept; - // -------------------------------------------------------------------------------------------- + + /* -------------------------------------------------------------------------------------------- + * Model identifier assignment operator. + */ CAutomobile & operator = (SQInt32 id) noexcept; - // -------------------------------------------------------------------------------------------- + + /* -------------------------------------------------------------------------------------------- + * Equality comparison operator. + */ bool operator == (const CAutomobile & a) const noexcept; + + /* -------------------------------------------------------------------------------------------- + * Inequality comparison operator. + */ bool operator != (const CAutomobile & a) const noexcept; + + /* -------------------------------------------------------------------------------------------- + * Less than comparison operator. + */ bool operator < (const CAutomobile & a) const noexcept; + + /* -------------------------------------------------------------------------------------------- + * Greater than comparison operator. + */ bool operator > (const CAutomobile & a) const noexcept; + + /* -------------------------------------------------------------------------------------------- + * Less than or equal comparison operator. + */ bool operator <= (const CAutomobile & a) const noexcept; + + /* -------------------------------------------------------------------------------------------- + * Greater than or equal comparison operator. + */ bool operator >= (const CAutomobile & a) const noexcept; - // -------------------------------------------------------------------------------------------- - operator SQInt32 () const noexcept { return m_ID; } - operator bool () const noexcept { return IsAutomobileValid(m_ID); } - // -------------------------------------------------------------------------------------------- - bool operator ! () const noexcept { return !IsAutomobileValid(m_ID); } - // -------------------------------------------------------------------------------------------- + + /* -------------------------------------------------------------------------------------------- + * Implicit conversion to model identifier. + */ + operator SQInt32 () const noexcept + { + return m_ID; + } + + /* -------------------------------------------------------------------------------------------- + * Implicit conversion to boolean. + */ + operator bool () const noexcept + { + return IsAutomobileValid(m_ID); + } + + /* -------------------------------------------------------------------------------------------- + * Negation operator. + */ + bool operator ! () const noexcept + { + return !IsAutomobileValid(m_ID); + } + + /* -------------------------------------------------------------------------------------------- + * Used by the script to compare two instances of this type. + */ SQInteger Cmp(const CAutomobile & a) const noexcept; - // -------------------------------------------------------------------------------------------- + + /* -------------------------------------------------------------------------------------------- + * Convert this type to a string. + */ const SQChar * ToString() const noexcept; - // -------------------------------------------------------------------------------------------- + + /* -------------------------------------------------------------------------------------------- + * Retrieve the identifier referenced by this instance. + */ SQInteger GetID() const noexcept; + + /* -------------------------------------------------------------------------------------------- + * Change the identifier referenced by this instance. + */ void SetID(SQInt32 id) noexcept; - // -------------------------------------------------------------------------------------------- + + /* -------------------------------------------------------------------------------------------- + * Set the identifier that this insance should reference and + * get a reference to the instance to chain operations. + */ CAutomobile & SetnGet(SQInt32 id) noexcept; - // -------------------------------------------------------------------------------------------- + + /* -------------------------------------------------------------------------------------------- + * Retrieve the global tag. + */ const SQChar * GetGlobalTag() const noexcept; + + /* -------------------------------------------------------------------------------------------- + * Change the global tag. + */ void SetGlobalTag(const SQChar * tag) const noexcept; - // -------------------------------------------------------------------------------------------- + + /* -------------------------------------------------------------------------------------------- + * Retrieve the global data. + */ SqObj & GetGlobalData() const noexcept; + + /* -------------------------------------------------------------------------------------------- + * Change the global data. + */ void SetGlobalData(SqObj & data) const noexcept; - // -------------------------------------------------------------------------------------------- + + /* -------------------------------------------------------------------------------------------- + * Retrieve the local tag. + */ const SQChar * GetLocalTag() const noexcept; + + /* -------------------------------------------------------------------------------------------- + * Change the local tag. + */ void SetLocalTag(const SQChar * tag) noexcept; - // -------------------------------------------------------------------------------------------- + + /* -------------------------------------------------------------------------------------------- + * Retrieve the local data. + */ SqObj & GetLocalData() noexcept; + + /* -------------------------------------------------------------------------------------------- + * Change the local data. + */ void SetLocalData(SqObj & data) noexcept; - // -------------------------------------------------------------------------------------------- + + /* -------------------------------------------------------------------------------------------- + * See whether the referenced model identifier is valid. + */ bool IsValid() const noexcept; - // -------------------------------------------------------------------------------------------- + + /* -------------------------------------------------------------------------------------------- + * Retrieve the name of the referenced model. + */ const SQChar * GetName() const noexcept; - // -------------------------------------------------------------------------------------------- - Reference < CVehicle > Create(SQInt32 world, const Vector3 & pos, SQFloat angle, \ + + /* -------------------------------------------------------------------------------------------- + * Change the identifier of the referenced model. + */ + void SetName(const SQChar * name) noexcept; + + /* -------------------------------------------------------------------------------------------- + * Create a vehicle instance using the referenced model. + */ + Reference < CVehicle > Create(SQInt32 world, const Vector3 & pos, SQFloat angle, SQInt32 header, SqObj & payload) const noexcept; - Reference < CVehicle > Create(SQInt32 world, const Vector3 & pos, SQFloat angle, \ - SQInt32 primary, SQInt32 secondary, SQInt32 header, \ + + /* -------------------------------------------------------------------------------------------- + * Create a vehicle instance using the referenced model. + */ + Reference < CVehicle > Create(SQInt32 world, const Vector3 & pos, SQFloat angle, + SQInt32 primary, SQInt32 secondary, SQInt32 header, SqObj & payload) const noexcept; - Reference < CVehicle > Create(SQInt32 world, SQFloat x, SQFloat y, SQFloat z, SQFloat angle, \ + + /* -------------------------------------------------------------------------------------------- + * Create a vehicle instance using the referenced model. + */ + Reference < CVehicle > Create(SQInt32 world, SQFloat x, SQFloat y, SQFloat z, SQFloat angle, SQInt32 header, SqObj & payload) const noexcept; - Reference < CVehicle > Create(SQInt32 world, SQFloat x, SQFloat y, SQFloat z, SQFloat angle, \ - SQInt32 primary, SQInt32 secondary, SQInt32 header, \ + + /* -------------------------------------------------------------------------------------------- + * Create a vehicle instance using the referenced model. + */ + Reference < CVehicle > Create(SQInt32 world, SQFloat x, SQFloat y, SQFloat z, SQFloat angle, + SQInt32 primary, SQInt32 secondary, SQInt32 header, SqObj & payload) const noexcept; + private: - // -------------------------------------------------------------------------------------------- + + + /* -------------------------------------------------------------------------------------------- + * The identifier of the referenced model. + */ SQInt32 m_ID; - // -------------------------------------------------------------------------------------------- - String m_Name; - // -------------------------------------------------------------------------------------------- + + /* -------------------------------------------------------------------------------------------- + * The local tag associated with this instance. + */ SqTag m_Tag; + + /* -------------------------------------------------------------------------------------------- + * The local data associated with this instance. + */ SqObj m_Data; };