2015-09-30 02:56:11 +02:00
|
|
|
#include "Misc/Weapon.hpp"
|
|
|
|
#include "Entity.hpp"
|
|
|
|
#include "Register.hpp"
|
|
|
|
#include "Core.hpp"
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
namespace SqMod {
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
const CWeapon CWeapon::NIL = CWeapon();
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
CWeapon::CWeapon()
|
2015-10-29 21:58:49 +01:00
|
|
|
: m_ID(SQMOD_UNKNOWN), m_Ammo(0)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
CWeapon::CWeapon(SQInt32 id)
|
2015-09-30 02:56:11 +02:00
|
|
|
: CWeapon(id, 0)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
CWeapon::CWeapon(SQInt32 id, SQInt32 ammo)
|
2015-10-29 21:58:49 +01:00
|
|
|
: m_ID(VALID_ENTITYGETEX(id, Max)), m_Ammo(ammo)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
CWeapon::CWeapon(const SQChar * name, SQInt32 id, SQInt32 ammo)
|
2015-10-29 21:58:49 +01:00
|
|
|
: m_ID(GetWeaponID(name)), m_Ammo(ammo)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2015-10-29 21:58:49 +01:00
|
|
|
if (VALID_ENTITYEX(m_ID, Max))
|
|
|
|
{
|
|
|
|
m_ID = id;
|
|
|
|
}
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
CWeapon::CWeapon(const CWeapon & w)
|
2015-09-30 02:56:11 +02:00
|
|
|
: m_ID(w.m_ID)
|
|
|
|
, m_Ammo(w.m_Ammo)
|
|
|
|
, m_Tag(w.m_Tag)
|
|
|
|
, m_Data(w.m_Data)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
CWeapon::CWeapon(CWeapon && w)
|
2015-09-30 02:56:11 +02:00
|
|
|
: m_ID(w.m_ID)
|
|
|
|
, m_Ammo(w.m_Ammo)
|
|
|
|
, m_Tag(w.m_Tag)
|
|
|
|
, m_Data(w.m_Data)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
CWeapon::~CWeapon()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
CWeapon & CWeapon::operator = (const CWeapon & w)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
m_ID = w.m_ID;
|
|
|
|
m_Ammo = w.m_Ammo;
|
|
|
|
m_Tag = w.m_Tag;
|
|
|
|
m_Data = w.m_Data;
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
CWeapon & CWeapon::operator = (CWeapon && w)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
m_ID = w.m_ID;
|
|
|
|
m_Ammo = w.m_Ammo;
|
|
|
|
m_Tag = w.m_Tag;
|
|
|
|
m_Data = w.m_Data;
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
CWeapon & CWeapon::operator = (SQInt32 id)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2015-10-29 21:58:49 +01:00
|
|
|
m_ID = VALID_ENTITYGETEX(id, Max);
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
bool CWeapon::operator == (const CWeapon & w) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return (m_ID == w.m_ID);
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
bool CWeapon::operator != (const CWeapon & w) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return (m_ID != w.m_ID);
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
bool CWeapon::operator < (const CWeapon & w) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return (m_ID < w.m_ID);
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
bool CWeapon::operator > (const CWeapon & w) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return (m_ID < w.m_ID);
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
bool CWeapon::operator <= (const CWeapon & w) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return (m_ID <= w.m_ID);
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
bool CWeapon::operator >= (const CWeapon & w) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return (m_ID >= w.m_ID);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
SQInteger CWeapon::Cmp(const CWeapon & w) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2015-10-29 21:58:49 +01:00
|
|
|
if (m_ID == w.m_ID)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else if (m_ID > w.m_ID)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
const SQChar * CWeapon::ToString() const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2015-10-29 21:58:49 +01:00
|
|
|
return GetWeaponName(m_ID);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
SQInteger CWeapon::GetID() const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return m_ID;
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
void CWeapon::SetID(SQInt32 id)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2015-10-29 21:58:49 +01:00
|
|
|
m_ID = VALID_ENTITYGETEX(id, Max);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
CWeapon & CWeapon::SetnGet(SQInt32 id)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2015-10-29 21:58:49 +01:00
|
|
|
m_ID = VALID_ENTITYGETEX(id, Max);
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
const SQChar * CWeapon::GetGlobalTag() const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return GlobalTag(m_ID);
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
void CWeapon::SetGlobalTag(const SQChar * tag) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
GlobalTag(m_ID, tag);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
SqObj & CWeapon::GetGlobalData() const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return GlobalData(m_ID);
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
void CWeapon::SetGlobalData(SqObj & data) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
GlobalData(m_ID, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
const SQChar * CWeapon::GetLocalTag() const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return m_Tag.c_str();
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
void CWeapon::SetLocalTag(const SQChar * tag)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
m_Tag = tag;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
SqObj & CWeapon::GetLocalData()
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return m_Data;
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
void CWeapon::SetLocalData(SqObj & data)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
m_Data = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
bool CWeapon::IsValid() const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2015-10-29 21:58:49 +01:00
|
|
|
return (VALID_ENTITYEX(m_ID, Max));
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
const SQChar * CWeapon::GetName() const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2015-10-29 21:58:49 +01:00
|
|
|
return GetWeaponName(m_ID);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
void CWeapon::SetName(const SQChar * name)
|
2015-10-29 21:58:49 +01:00
|
|
|
{
|
|
|
|
m_ID = GetWeaponID(name);
|
|
|
|
m_ID = VALID_ENTITYGETEX(m_ID, Max);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
SQInteger CWeapon::GetAmmo() const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return m_Ammo;
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
void CWeapon::SetAmmo(SQInt32 amount)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
m_Ammo = amount;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
bool CWeapon::IsNatural() const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return IsWeaponNatural(m_ID);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
SQFloat CWeapon::GetDataValue(SQInt32 field) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return _Func->GetWeaponDataValue(m_ID, field);
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
void CWeapon::SetDataValue(SQInt32 field, SQFloat value) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
_Func->SetWeaponDataValue(m_ID, field, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
void CWeapon::ResetData() const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
_Func->ResetWeaponData(m_ID);
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
void CWeapon::ResetData(SQInt32 field) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
_Func->ResetWeaponDataValue(m_ID, field);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
bool CWeapon::IsDataModified(SQInt32 field) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return _Func->IsWeaponDataValueModified(m_ID, field);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
void CWeapon::SetOn(const Reference< CPlayer > & player) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
if (*this && player)
|
|
|
|
{
|
|
|
|
_Func->SetPlayerWeapon(player, m_ID, m_Ammo);
|
|
|
|
}
|
|
|
|
else if (!player)
|
|
|
|
{
|
|
|
|
LogErr(_SC("Attempting to <set player weapon> using an invalid argument: %d"), _SCI32(player));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LogErr(_SC("Attempting to <set player weapon> using an invalid instance: %d"), m_ID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
void CWeapon::GiveTo(const Reference< CPlayer > & player) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
if (*this && player)
|
|
|
|
{
|
|
|
|
_Func->GivePlayerWeapon(player, m_ID, m_Ammo);
|
|
|
|
}
|
|
|
|
else if (!player)
|
|
|
|
{
|
|
|
|
LogErr(_SC("Attempting to <give player weapon> using an invalid argument: %d"), _SCI32(player));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LogErr(_SC("Attempting to <give player weapon> using an invalid instance: %d"), m_ID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
void CWeapon::SetOn(const Reference< CPlayer > & player, SQInt32 ammo) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
if (*this && player)
|
|
|
|
{
|
|
|
|
_Func->SetPlayerWeapon(player, m_ID, ammo);
|
|
|
|
}
|
|
|
|
else if (!player)
|
|
|
|
{
|
|
|
|
LogErr(_SC("Attempting to <set player weapon> using an invalid argument: %d"), _SCI32(player));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LogErr(_SC("Attempting to <set player weapon> using an invalid instance: %d"), m_ID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
void CWeapon::GiveTo(const Reference< CPlayer > & player, SQInt32 ammo) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
if (*this && player)
|
|
|
|
{
|
|
|
|
_Func->GivePlayerWeapon(player, m_ID, ammo);
|
|
|
|
}
|
|
|
|
else if (!player)
|
|
|
|
{
|
|
|
|
LogErr(_SC("Attempting to <give player weapon> using an invalid argument: %d"), _SCI32(player));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LogErr(_SC("Attempting to <give player weapon> using an invalid instance: %d"), m_ID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ================================================================================================
|
|
|
|
bool Register_CWeapon(HSQUIRRELVM vm)
|
|
|
|
{
|
|
|
|
// Output debugging information
|
|
|
|
LogDbg("Beginning registration of <CWeapon> type");
|
|
|
|
// Attempt to register the specified type
|
|
|
|
Sqrat::RootTable(vm).Bind(_SC("CWeapon"), Sqrat::Class< CWeapon >(vm, _SC("CWeapon"))
|
2015-10-29 21:58:49 +01:00
|
|
|
/* Constructors */
|
2015-09-30 02:56:11 +02:00
|
|
|
.Ctor()
|
|
|
|
.Ctor< SQInt32 >()
|
|
|
|
.Ctor< SQInt32, SQInt32 >()
|
|
|
|
.Ctor< const SQChar *, SQInt32, SQInt32 >()
|
2015-10-29 21:58:49 +01:00
|
|
|
/* Metamethods */
|
2015-09-30 02:56:11 +02:00
|
|
|
.Func(_SC("_cmp"), &CWeapon::Cmp)
|
2015-10-29 21:58:49 +01:00
|
|
|
/* Properties */
|
2015-09-30 02:56:11 +02:00
|
|
|
.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)
|
2015-10-29 21:58:49 +01:00
|
|
|
.Prop(_SC("name"), &CWeapon::GetName, &CWeapon::SetName)
|
2015-09-30 02:56:11 +02:00
|
|
|
.Prop(_SC("valid"), &CWeapon::IsValid)
|
|
|
|
.Prop(_SC("ammo"), &CWeapon::GetAmmo, &CWeapon::SetAmmo)
|
|
|
|
.Prop(_SC("natural"), &CWeapon::IsNatural)
|
2015-10-29 21:58:49 +01:00
|
|
|
/* Functions */
|
2015-09-30 02:56:11 +02:00
|
|
|
.Func(_SC("setng"), &CWeapon::SetnGet)
|
|
|
|
.Func(_SC("get_value"), &CWeapon::GetDataValue)
|
|
|
|
.Func(_SC("set_value"), &CWeapon::SetDataValue)
|
|
|
|
.Func(_SC("is_modified"), &CWeapon::IsDataModified)
|
2015-10-29 21:58:49 +01:00
|
|
|
/* Overloads */
|
2015-09-30 02:56:11 +02:00
|
|
|
.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)
|
|
|
|
.Overload< void (CWeapon::*)(const Reference< CPlayer > &, SQInt32) const >(_SC("set_on"), &CWeapon::SetOn)
|
|
|
|
.Overload< void (CWeapon::*)(const Reference< CPlayer > &) const >(_SC("give_to"), &CWeapon::GiveTo)
|
|
|
|
.Overload< void (CWeapon::*)(const Reference< CPlayer > &, SQInt32) const >(_SC("give_to"), &CWeapon::GiveTo)
|
|
|
|
);
|
|
|
|
// Output debugging information
|
|
|
|
LogDbg("Registration of <CWeapon> type was successful");
|
|
|
|
// Registration succeeded
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // Namespace:: SqMod
|