mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2024-11-08 00:37:15 +01:00
Documented the Weapon type and made minor fixes.
This commit is contained in:
parent
14cba720dd
commit
6f3579192a
@ -11,7 +11,7 @@ const CWeapon CWeapon::NIL = CWeapon();
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CWeapon::CWeapon() noexcept
|
||||
: m_ID(SQMOD_UNKNOWN), m_Ammo(0), m_Name()
|
||||
: m_ID(SQMOD_UNKNOWN), m_Ammo(0)
|
||||
{
|
||||
|
||||
}
|
||||
@ -23,22 +23,24 @@ CWeapon::CWeapon(SQInt32 id) noexcept
|
||||
}
|
||||
|
||||
CWeapon::CWeapon(SQInt32 id, SQInt32 ammo) noexcept
|
||||
: m_ID(VALID_ENTITYGETEX(id, Max)), m_Ammo(ammo), m_Name(GetWeaponName(id))
|
||||
: m_ID(VALID_ENTITYGETEX(id, Max)), m_Ammo(ammo)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CWeapon::CWeapon(const SQChar * name, SQInt32 id, SQInt32 ammo) noexcept
|
||||
: CWeapon((IsWeaponValid(GetWeaponID(name)) ? GetWeaponID(name) : id), ammo)
|
||||
: m_ID(GetWeaponID(name)), m_Ammo(ammo)
|
||||
{
|
||||
|
||||
if (VALID_ENTITYEX(m_ID, Max))
|
||||
{
|
||||
m_ID = id;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CWeapon::CWeapon(const CWeapon & w) noexcept
|
||||
: m_ID(w.m_ID)
|
||||
, m_Ammo(w.m_Ammo)
|
||||
, m_Name(w.m_Name)
|
||||
, m_Tag(w.m_Tag)
|
||||
, m_Data(w.m_Data)
|
||||
{
|
||||
@ -48,7 +50,6 @@ CWeapon::CWeapon(const CWeapon & w) noexcept
|
||||
CWeapon::CWeapon(CWeapon && w) noexcept
|
||||
: m_ID(w.m_ID)
|
||||
, m_Ammo(w.m_Ammo)
|
||||
, m_Name(w.m_Name)
|
||||
, m_Tag(w.m_Tag)
|
||||
, m_Data(w.m_Data)
|
||||
{
|
||||
@ -66,7 +67,6 @@ CWeapon & CWeapon::operator = (const CWeapon & w) noexcept
|
||||
{
|
||||
m_ID = w.m_ID;
|
||||
m_Ammo = w.m_Ammo;
|
||||
m_Name = w.m_Name;
|
||||
m_Tag = w.m_Tag;
|
||||
m_Data = w.m_Data;
|
||||
|
||||
@ -77,7 +77,6 @@ CWeapon & CWeapon::operator = (CWeapon && w) noexcept
|
||||
{
|
||||
m_ID = w.m_ID;
|
||||
m_Ammo = w.m_Ammo;
|
||||
m_Name = w.m_Name;
|
||||
m_Tag = w.m_Tag;
|
||||
m_Data = w.m_Data;
|
||||
|
||||
@ -87,11 +86,7 @@ CWeapon & CWeapon::operator = (CWeapon && w) noexcept
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CWeapon & CWeapon::operator = (SQInt32 id) noexcept
|
||||
{
|
||||
if (m_ID != id)
|
||||
{
|
||||
m_Name = GetWeaponName(id);
|
||||
m_ID = id;
|
||||
}
|
||||
m_ID = VALID_ENTITYGETEX(id, Max);
|
||||
|
||||
return *this;
|
||||
}
|
||||
@ -130,13 +125,24 @@ bool CWeapon::operator >= (const CWeapon & w) const noexcept
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInteger CWeapon::Cmp(const CWeapon & w) const noexcept
|
||||
{
|
||||
return m_ID == w.m_ID ? 0 : (m_ID > w.m_ID ? 1 : -1);
|
||||
if (m_ID == w.m_ID)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if (m_ID > w.m_ID)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const SQChar * CWeapon::ToString() const noexcept
|
||||
{
|
||||
return m_Name.c_str();
|
||||
return GetWeaponName(m_ID);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -147,21 +153,13 @@ SQInteger CWeapon::GetID() const noexcept
|
||||
|
||||
void CWeapon::SetID(SQInt32 id) noexcept
|
||||
{
|
||||
if (m_ID != id)
|
||||
{
|
||||
m_Name = GetWeaponName(id);
|
||||
m_ID = id;
|
||||
}
|
||||
m_ID = VALID_ENTITYGETEX(id, Max);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CWeapon & CWeapon::SetnGet(SQInt32 id) noexcept
|
||||
{
|
||||
if (m_ID != id)
|
||||
{
|
||||
m_Name = GetWeaponName(id);
|
||||
m_ID = id;
|
||||
}
|
||||
m_ID = VALID_ENTITYGETEX(id, Max);
|
||||
|
||||
return *this;
|
||||
}
|
||||
@ -213,13 +211,20 @@ void CWeapon::SetLocalData(SqObj & data) noexcept
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool CWeapon::IsValid() const noexcept
|
||||
{
|
||||
return (m_ID > 0);
|
||||
return (VALID_ENTITYEX(m_ID, Max));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const SQChar * CWeapon::GetName() const noexcept
|
||||
{
|
||||
return m_Name.c_str();
|
||||
return GetWeaponName(m_ID);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CWeapon::SetName(const SQChar * name) noexcept
|
||||
{
|
||||
m_ID = GetWeaponID(name);
|
||||
m_ID = VALID_ENTITYGETEX(m_ID, Max);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -339,28 +344,29 @@ bool Register_CWeapon(HSQUIRRELVM vm)
|
||||
LogDbg("Beginning registration of <CWeapon> type");
|
||||
// Attempt to register the specified type
|
||||
Sqrat::RootTable(vm).Bind(_SC("CWeapon"), Sqrat::Class< CWeapon >(vm, _SC("CWeapon"))
|
||||
/* Constructors */
|
||||
.Ctor()
|
||||
.Ctor< SQInt32 >()
|
||||
.Ctor< SQInt32, SQInt32 >()
|
||||
.Ctor< const SQChar *, SQInt32, SQInt32 >()
|
||||
|
||||
/* Metamethods */
|
||||
.Func(_SC("_cmp"), &CWeapon::Cmp)
|
||||
|
||||
/* Properties */
|
||||
.Prop(_SC("id"), &CWeapon::GetID, &CWeapon::SetID)
|
||||
.Prop(_SC("gtag"), &CWeapon::GetGlobalTag, &CWeapon::SetGlobalTag)
|
||||
.Prop(_SC("gdata"), &CWeapon::GetGlobalData, &CWeapon::SetGlobalData)
|
||||
.Prop(_SC("ltag"), &CWeapon::GetLocalTag, &CWeapon::SetLocalTag)
|
||||
.Prop(_SC("ldata"), &CWeapon::GetLocalData, &CWeapon::SetLocalData)
|
||||
.Prop(_SC("name"), &CWeapon::GetName, &CWeapon::SetName)
|
||||
.Prop(_SC("valid"), &CWeapon::IsValid)
|
||||
.Prop(_SC("name"), &CWeapon::GetName)
|
||||
.Prop(_SC("ammo"), &CWeapon::GetAmmo, &CWeapon::SetAmmo)
|
||||
.Prop(_SC("natural"), &CWeapon::IsNatural)
|
||||
|
||||
/* Functions */
|
||||
.Func(_SC("setng"), &CWeapon::SetnGet)
|
||||
.Func(_SC("get_value"), &CWeapon::GetDataValue)
|
||||
.Func(_SC("set_value"), &CWeapon::SetDataValue)
|
||||
.Func(_SC("is_modified"), &CWeapon::IsDataModified)
|
||||
|
||||
/* Overloads */
|
||||
.Overload< void (CWeapon::*)(void) const >(_SC("reset_data"), &CWeapon::ResetData)
|
||||
.Overload< void (CWeapon::*)(SQInt32) const >(_SC("reset_data"), &CWeapon::ResetData)
|
||||
.Overload< void (CWeapon::*)(const Reference< CPlayer > &) const >(_SC("set_on"), &CWeapon::SetOn)
|
||||
|
@ -7,90 +7,284 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Class responsible for managing and interacting with weapon models.
|
||||
*/
|
||||
class CWeapon : public IdentifierStorage< CWeapon, SQMOD_WEAPONID_CAP >
|
||||
{
|
||||
public:
|
||||
// --------------------------------------------------------------------------------------------
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Helper member for times when a null reference to an instance of this type is needed.
|
||||
*/
|
||||
static const CWeapon NIL;
|
||||
// --------------------------------------------------------------------------------------------
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default constructor.
|
||||
*/
|
||||
CWeapon() noexcept;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Construct an instance of this type and reference the model specified.
|
||||
*/
|
||||
CWeapon(SQInt32 id) noexcept;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Construct an instance of this type and reference the model specified.
|
||||
*/
|
||||
CWeapon(SQInt32 id, SQInt32 ammo) noexcept;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Construct an instance of this type and reference the model extracted from the specified name.
|
||||
*/
|
||||
CWeapon(const SQChar * name, SQInt32 id, SQInt32 ammo) noexcept;
|
||||
// --------------------------------------------------------------------------------------------
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor.
|
||||
*/
|
||||
CWeapon(const CWeapon & w) noexcept;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor.
|
||||
*/
|
||||
CWeapon(CWeapon && w) noexcept;
|
||||
// --------------------------------------------------------------------------------------------
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~CWeapon() noexcept;
|
||||
// --------------------------------------------------------------------------------------------
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator.
|
||||
*/
|
||||
CWeapon & operator = (const CWeapon & w) noexcept;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move assignment operator.
|
||||
*/
|
||||
CWeapon & operator = (CWeapon && w) noexcept;
|
||||
// --------------------------------------------------------------------------------------------
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Model identifier assignment operator.
|
||||
*/
|
||||
CWeapon & operator = (SQInt32 id) noexcept;
|
||||
// --------------------------------------------------------------------------------------------
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Equality comparison operator.
|
||||
*/
|
||||
bool operator == (const CWeapon & w) const noexcept;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Inequality comparison operator.
|
||||
*/
|
||||
bool operator != (const CWeapon & w) const noexcept;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Less than comparison operator.
|
||||
*/
|
||||
bool operator < (const CWeapon & w) const noexcept;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Greater than comparison operator.
|
||||
*/
|
||||
bool operator > (const CWeapon & w) const noexcept;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Less than or equal comparison operator.
|
||||
*/
|
||||
bool operator <= (const CWeapon & w) const noexcept;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Greater than or equal comparison operator.
|
||||
*/
|
||||
bool operator >= (const CWeapon & w) const noexcept;
|
||||
// --------------------------------------------------------------------------------------------
|
||||
operator SQInt32 () const noexcept { return m_ID; }
|
||||
operator bool () const noexcept { return IsWeaponValid(m_ID); }
|
||||
// --------------------------------------------------------------------------------------------
|
||||
bool operator ! () const noexcept { return !IsWeaponValid(m_ID); }
|
||||
// --------------------------------------------------------------------------------------------
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Implicit conversion to model identifier.
|
||||
*/
|
||||
operator SQInt32 () const noexcept
|
||||
{
|
||||
return m_ID;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Implicit conversion to boolean.
|
||||
*/
|
||||
operator bool () const noexcept
|
||||
{
|
||||
return IsWeaponValid(m_ID);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Negation operator.
|
||||
*/
|
||||
bool operator ! () const noexcept
|
||||
{
|
||||
return !IsWeaponValid(m_ID);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Used by the script to compare two instances of this type.
|
||||
*/
|
||||
SQInteger Cmp(const CWeapon & w) 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.
|
||||
*/
|
||||
CWeapon & 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;
|
||||
// --------------------------------------------------------------------------------------------
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Change the identifier of the referenced model.
|
||||
*/
|
||||
void SetName(const SQChar * name) noexcept;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the ammount of ammo associated with this instance.
|
||||
*/
|
||||
SQInteger GetAmmo() const noexcept;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Change the ammount of ammo associated with this instance.
|
||||
*/
|
||||
void SetAmmo(SQInt32 amount) noexcept;
|
||||
// --------------------------------------------------------------------------------------------
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See whether the referenced weapon identifier points to a weapon that may not be used by
|
||||
* another player to perform a kill. Such as a player fall, drown, explosion etc.
|
||||
*/
|
||||
bool IsNatural() const noexcept;
|
||||
// --------------------------------------------------------------------------------------------
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the value in the specified field from the weapon data.
|
||||
*/
|
||||
SQFloat GetDataValue(SQInt32 field) const noexcept;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Change the value in the specified field from the weapon data.
|
||||
*/
|
||||
void SetDataValue(SQInt32 field, SQFloat value) const noexcept;
|
||||
// --------------------------------------------------------------------------------------------
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Reset the data for the referenced weapon identifier.
|
||||
*/
|
||||
void ResetData() const noexcept;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Reset the foe;d data data for the referenced weapon identifier.
|
||||
*/
|
||||
void ResetData(SQInt32 field) const noexcept;
|
||||
// --------------------------------------------------------------------------------------------
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See whether the data at the specified field was modified.
|
||||
*/
|
||||
bool IsDataModified(SQInt32 field) const noexcept;
|
||||
// --------------------------------------------------------------------------------------------
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set the weapon of the specified player instance to the referenced weapon identifier.
|
||||
*/
|
||||
void SetOn(const Reference< CPlayer > & player) const noexcept;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Give the referenced weapon identifier to the specified player instance.
|
||||
*/
|
||||
void GiveTo(const Reference< CPlayer > & player) const noexcept;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set the weapon of the specified player instance to the referenced weapon identifier.
|
||||
*/
|
||||
void SetOn(const Reference< CPlayer > & player, SQInt32 ammo) const noexcept;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Give the referenced weapon identifier to the specified player instance.
|
||||
*/
|
||||
void GiveTo(const Reference< CPlayer > & player, SQInt32 ammo) const noexcept;
|
||||
|
||||
private:
|
||||
// --------------------------------------------------------------------------------------------
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* The identifier of the referenced model.
|
||||
*/
|
||||
SQInt32 m_ID;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* The ammo associated with this instance.
|
||||
*/
|
||||
SQInt32 m_Ammo;
|
||||
// --------------------------------------------------------------------------------------------
|
||||
String m_Name;
|
||||
// --------------------------------------------------------------------------------------------
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* The local tag associated with this instance
|
||||
*/
|
||||
SqTag m_Tag;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* The local data associated with this instance.
|
||||
*/
|
||||
SqObj m_Data;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user