1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-09 01:07:16 +01:00
SqMod/source/Misc/Automobile.cpp

290 lines
8.8 KiB
C++
Raw Normal View History

2015-09-30 02:56:11 +02:00
#include "Misc/Automobile.hpp"
#include "Base/Color3.hpp"
#include "Base/Vector3.hpp"
#include "Entity.hpp"
#include "Register.hpp"
#include "Core.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
const CAutomobile CAutomobile::NIL;
// ------------------------------------------------------------------------------------------------
CAutomobile::CAutomobile() noexcept
: m_ID(SQMOD_UNKNOWN)
2015-09-30 02:56:11 +02:00
{
}
CAutomobile::CAutomobile(SQInt32 id) noexcept
: m_ID(VALID_ENTITYGETEX(id, Max))
2015-09-30 02:56:11 +02:00
{
}
CAutomobile::CAutomobile(const SQChar * name, SQInt32 id) noexcept
: m_ID(GetAutomobileID(name))
2015-09-30 02:56:11 +02:00
{
if (VALID_ENTITYEX(m_ID, Max))
{
m_ID = id;
}
2015-09-30 02:56:11 +02:00
}
// ------------------------------------------------------------------------------------------------
CAutomobile::CAutomobile(const CAutomobile & a) noexcept
: m_ID(a.m_ID)
, m_Tag(a.m_Tag)
, m_Data(a.m_Data)
{
}
CAutomobile::CAutomobile(CAutomobile && a) noexcept
: m_ID(a.m_ID)
, m_Tag(a.m_Tag)
, m_Data(a.m_Data)
{
}
// ------------------------------------------------------------------------------------------------
CAutomobile::~CAutomobile()
{
}
// ------------------------------------------------------------------------------------------------
CAutomobile & CAutomobile::operator = (const CAutomobile & a) noexcept
{
m_ID = a.m_ID;
m_Tag = a.m_Tag;
m_Data = a.m_Data;
return *this;
}
CAutomobile & CAutomobile::operator = (CAutomobile && a) noexcept
{
m_ID = a.m_ID;
m_Tag = a.m_Tag;
m_Data = a.m_Data;
return *this;
}
// ------------------------------------------------------------------------------------------------
CAutomobile & CAutomobile::operator = (SQInt32 id) noexcept
{
m_ID = VALID_ENTITYGETEX(id, Max);
2015-09-30 02:56:11 +02:00
return *this;
}
// ------------------------------------------------------------------------------------------------
bool CAutomobile::operator == (const CAutomobile & a) const noexcept
{
return (m_ID == a.m_ID);
}
bool CAutomobile::operator != (const CAutomobile & a) const noexcept
{
return (m_ID != a.m_ID);
}
bool CAutomobile::operator < (const CAutomobile & a) const noexcept
{
return (m_ID < a.m_ID);
}
bool CAutomobile::operator > (const CAutomobile & a) const noexcept
{
return (m_ID < a.m_ID);
}
bool CAutomobile::operator <= (const CAutomobile & a) const noexcept
{
return (m_ID <= a.m_ID);
}
bool CAutomobile::operator >= (const CAutomobile & a) const noexcept
{
return (m_ID >= a.m_ID);
}
// ------------------------------------------------------------------------------------------------
SQInteger CAutomobile::Cmp(const CAutomobile & a) const noexcept
{
if (m_ID == a.m_ID)
{
return 0;
}
else if (m_ID > a.m_ID)
{
return 1;
}
else
{
return -1;
}
2015-09-30 02:56:11 +02:00
}
// ------------------------------------------------------------------------------------------------
const SQChar * CAutomobile::ToString() const noexcept
{
return GetAutomobileName(m_ID);
2015-09-30 02:56:11 +02:00
}
// ------------------------------------------------------------------------------------------------
SQInteger CAutomobile::GetID() const noexcept
{
return m_ID;
}
void CAutomobile::SetID(SQInt32 id) noexcept
{
m_ID = VALID_ENTITYGETEX(id, Max);
2015-09-30 02:56:11 +02:00
}
// ------------------------------------------------------------------------------------------------
CAutomobile & CAutomobile::SetnGet(SQInt32 id) noexcept
{
m_ID = VALID_ENTITYGETEX(id, Max);
2015-09-30 02:56:11 +02:00
return *this;
}
// ------------------------------------------------------------------------------------------------
const SQChar * CAutomobile::GetGlobalTag() const noexcept
{
return GlobalTag(m_ID);
}
void CAutomobile::SetGlobalTag(const SQChar * tag) const noexcept
{
GlobalTag(m_ID, tag);
}
// ------------------------------------------------------------------------------------------------
SqObj & CAutomobile::GetGlobalData() const noexcept
{
return GlobalData(m_ID);
}
void CAutomobile::SetGlobalData(SqObj & data) const noexcept
{
GlobalData(m_ID, data);
}
// ------------------------------------------------------------------------------------------------
const SQChar * CAutomobile::GetLocalTag() const noexcept
{
return m_Tag.c_str();
}
void CAutomobile::SetLocalTag(const SQChar * tag) noexcept
{
m_Tag = tag;
}
// ------------------------------------------------------------------------------------------------
SqObj & CAutomobile::GetLocalData() noexcept
{
return m_Data;
}
void CAutomobile::SetLocalData(SqObj & data) noexcept
{
m_Data = data;
}
// ------------------------------------------------------------------------------------------------
bool CAutomobile::IsValid() const noexcept
{
return (VALID_ENTITYEX(m_ID, Max));
2015-09-30 02:56:11 +02:00
}
// ------------------------------------------------------------------------------------------------
const SQChar * CAutomobile::GetName() const noexcept
{
return GetAutomobileName(m_ID);
}
// ------------------------------------------------------------------------------------------------
void CAutomobile::SetName(const SQChar * name) noexcept
{
m_ID = GetAutomobileID(name);
m_ID = VALID_ENTITYGETEX(m_ID, Max);
2015-09-30 02:56:11 +02:00
}
// ------------------------------------------------------------------------------------------------
Reference< CVehicle > CAutomobile::Create(SQInt32 world, const Vector3 & pos, SQFloat angle,
SQInt32 header, SqObj & payload) const noexcept
2015-09-30 02:56:11 +02:00
{
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,
SqObj & payload) const noexcept
2015-09-30 02:56:11 +02:00
{
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,
SQInt32 header, SqObj & payload) const noexcept
2015-09-30 02:56:11 +02:00
{
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,
SqObj & payload) const noexcept
2015-09-30 02:56:11 +02:00
{
return _Core->CreateVehicle(*this, world, Vector3(x, y, z), angle, primary, secondary, header, payload);
}
// ================================================================================================
bool Register_CAutomobile(HSQUIRRELVM vm)
{
// Output debugging information
LogDbg("Beginning registration of <CAutomobile> type");
// Attempt to register the specified type
Sqrat::RootTable(vm).Bind(_SC("CAutomobile"), Sqrat::Class< CAutomobile >(vm, _SC("CAutomobile"))
/* Constructors */
2015-09-30 02:56:11 +02:00
.Ctor()
.Ctor< SQInt32 >()
.Ctor< const SQChar *, SQInt32 >()
/* Metamethods */
2015-09-30 02:56:11 +02:00
.Func(_SC("_cmp"), &CAutomobile::Cmp)
.Func(_SC("_tostring"), &CAutomobile::ToString)
/* Properties */
2015-09-30 02:56:11 +02:00
.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, &CAutomobile::SetName)
/* Functions */
2015-09-30 02:56:11 +02:00
.Func(_SC("setng"), &CAutomobile::SetnGet)
/* 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)
2015-09-30 02:56:11 +02:00
);
// Output debugging information
LogDbg("Registration of <CAutomobile> type was successful");
// Registration succeeded
return true;
}
} // Namespace:: SqMod