1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-08 00:37:15 +01:00

Untested implementation of the Checkpoint type.

This commit is contained in:
Sandu Liviu Catalin 2015-10-29 22:07:31 +02:00
parent f89e0d8cd6
commit 7fc53d8274
2 changed files with 303 additions and 11 deletions

View File

@ -5,24 +5,241 @@
namespace SqMod {
// ------------------------------------------------------------------------------------------------
bool Register_CCheckpoint(HSQUIRRELVM vm)
{
if (!Register_Reference< CCheckpoint >(vm, _SC("BaseCheckpoint")))
{
LogDbg("Unable to register the base class <BaseCheckpoint> for <CCheckpoint> type");
Color4 CCheckpoint::s_Color4;
Vector3 CCheckpoint::s_Vector3;
return false;
// ------------------------------------------------------------------------------------------------
SQUint32 CCheckpoint::s_ColorR;
SQUint32 CCheckpoint::s_ColorG;
SQUint32 CCheckpoint::s_ColorB;
SQUint32 CCheckpoint::s_ColorA;
// ------------------------------------------------------------------------------------------------
bool CCheckpoint::IsStreamedFor(const Reference< CPlayer > & player) const noexcept
{
if (VALID_ENTITY(m_ID) && player)
{
return _Func->IsCheckpointStreamedForPlayer(m_ID, player);
}
else if (!player)
{
LogWrn(_SC("Attempting to <see if checkpoint is streamed for player> using an invalid argument: %d"), _SCI32(player));
}
else
{
LogWrn(_SC("Attempting to <see if checkpoint is streamed for player> using an invalid reference: %d"), m_ID);
}
LogDbg("Beginning registration of <CCheckpoint> type");
return false;
}
// ------------------------------------------------------------------------------------------------
SQInt32 CCheckpoint::GetWorld() const noexcept
{
if (VALID_ENTITY(m_ID))
{
return _Func->GetCheckpointWorld(m_ID);
}
else
{
LogWrn(_SC("Attempting to <get checkpoint world> using an invalid reference: %d"), m_ID);
}
return SQMOD_UNKNOWN;
}
// ------------------------------------------------------------------------------------------------
void CCheckpoint::SetWorld(SQInt32 world) const noexcept
{
if (VALID_ENTITY(m_ID))
{
_Func->SetCheckpointWorld(m_ID, world);
}
else
{
LogWrn(_SC("Attempting to <set checkpoint world> using an invalid reference: %d"), m_ID);
}
}
// ------------------------------------------------------------------------------------------------
const Color4 & CCheckpoint::GetColor() const noexcept
{
// Clear any previous color
s_Color4.Clear();
// Attempt to retrieve the color
if (VALID_ENTITY(m_ID))
{
_Func->GetCheckpointColor(m_ID, &s_ColorR, &s_ColorG, &s_ColorB, &s_ColorA);
s_Color4.Set(s_ColorR, s_ColorG, s_ColorB, s_ColorA);
}
else
{
LogWrn(_SC("Attempting to <get checkpoint color> using an invalid reference: %d"), m_ID);
}
// Return the color that could be retrieved
return s_Color4;
}
// ------------------------------------------------------------------------------------------------
void CCheckpoint::SetColor(const Color4 & col) const noexcept
{
if (VALID_ENTITY(m_ID))
{
_Func->SetCheckpointColor(m_ID, col.r, col.g, col.b, col.a);
}
else
{
LogWrn(_SC("Attempting to <set checkpoint color> using an invalid reference: %d"), m_ID);
}
}
// ------------------------------------------------------------------------------------------------
void CCheckpoint::SetColorEx(Uint8 r, Uint8 g, Uint8 b, Uint8 a) const noexcept
{
if (VALID_ENTITY(m_ID))
{
_Func->SetCheckpointColor(m_ID, r, g, b, a);
}
else
{
LogWrn(_SC("Attempting to <set checkpoint color> using an invalid reference: %d"), m_ID);
}
}
// ------------------------------------------------------------------------------------------------
const Vector3 & CCheckpoint::GetPosition() const noexcept
{
// Clear any previous position
s_Vector3.Clear();
// Attempt to retrieve the position
if (VALID_ENTITY(m_ID))
{
_Func->GetCheckpointPos(m_ID, &s_Vector3.x, &s_Vector3.y, &s_Vector3.z);
}
else
{
LogWrn(_SC("Attempting to <get checkpoint position> using an invalid reference: %d"), m_ID);
}
// Return the position that could be retrieved
return s_Vector3;
}
// ------------------------------------------------------------------------------------------------
void CCheckpoint::SetPosition(const Vector3 & pos) const noexcept
{
if (VALID_ENTITY(m_ID))
{
_Func->SetCheckpointPos(m_ID, pos.x, pos.y, pos.z);
}
else
{
LogWrn(_SC("Attempting to <set checkpoint position> using an invalid reference: %d"), m_ID);
}
}
// ------------------------------------------------------------------------------------------------
void CCheckpoint::SetPositionEx(SQFloat x, SQFloat y, SQFloat z) const noexcept
{
if (VALID_ENTITY(m_ID))
{
_Func->SetCheckpointPos(m_ID, x, y, z);
}
else
{
LogWrn(_SC("Attempting to <set checkpoint position> using an invalid reference: %d"), m_ID);
}
}
// ------------------------------------------------------------------------------------------------
SQFloat CCheckpoint::GetRadius() const noexcept
{
if (VALID_ENTITY(m_ID))
{
return _Func->GetCheckpointRadius(m_ID);
}
else
{
LogWrn(_SC("Attempting to <get checkpoint radius> using an invalid reference: %d"), m_ID);
}
return 0.0;
}
// ------------------------------------------------------------------------------------------------
void CCheckpoint::SetRadius(SQFloat radius) const noexcept
{
if (VALID_ENTITY(m_ID))
{
_Func->SetCheckpointRadius(m_ID, radius);
}
else
{
LogWrn(_SC("Attempting to <set checkpoint radius> using an invalid reference: %d"), m_ID);
}
}
// ------------------------------------------------------------------------------------------------
Reference< CPlayer > CCheckpoint::GetOwner() const noexcept
{
if (VALID_ENTITY(m_ID))
{
return Reference< CPlayer >(_Func->GetCheckpointOwner(m_ID));
}
else
{
LogWrn(_SC("Attempting to <get checkpoint owner> using an invalid reference: %d"), m_ID);
}
return Reference< CPlayer >();
}
// ------------------------------------------------------------------------------------------------
SQInt32 CCheckpoint::GetOwnerID() const noexcept
{
if (VALID_ENTITY(m_ID))
{
return _Func->GetCheckpointOwner(m_ID);
}
else
{
LogWrn(_SC("Attempting to <get checkpoint owner id> using an invalid reference: %d"), m_ID);
}
return SQMOD_UNKNOWN;
}
// ================================================================================================
bool Register_CCheckpoint(HSQUIRRELVM vm)
{
// Attempt to register the base reference type before the actual implementation
if (!Register_Reference< CCheckpoint >(vm, _SC("BaseCheckpoint")))
{
LogFtl("Unable to register the base class <BaseCheckpoint> for <CCheckpoint> type");
// Registration failed
return false;
}
// Output debugging information
LogDbg("Beginning registration of <CCheckpoint> type");
// Attempt to register the actual reference that implements all of the entity functionality
Sqrat::RootTable(vm).Bind(_SC("CCheckpoint"), Sqrat::DerivedClass< CCheckpoint, Reference< CCheckpoint > >(vm, _SC("CCheckpoint"))
/* Constructors */
.Ctor()
.Ctor< SQInt32 >()
/* Properties */
.Prop(_SC("world"), &CCheckpoint::GetWorld, &CCheckpoint::SetWorld)
.Prop(_SC("color"), &CCheckpoint::GetColor, &CCheckpoint::SetColor)
.Prop(_SC("position"), &CCheckpoint::GetPosition, &CCheckpoint::SetPosition)
.Prop(_SC("radius"), &CCheckpoint::GetRadius, &CCheckpoint::SetRadius)
.Prop(_SC("owner"), &CCheckpoint::GetOwner)
.Prop(_SC("owner_id"), &CCheckpoint::GetOwnerID)
/* Functions */
.Func(_SC("streamed_for"), &CCheckpoint::IsStreamedFor)
.Func(_SC("set_color"), &CCheckpoint::SetColorEx)
.Func(_SC("set_position"), &CCheckpoint::SetPositionEx)
);
// Output debugging information
LogDbg("Registration of <CCheckpoint> type was successful");
// Registration succeeded
return true;
}

View File

@ -8,13 +8,88 @@
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* ...
* Class responsible for managing the referenced checkpoint instance.
*/
class CCheckpoint : public Reference< CCheckpoint >
{
public:
// --------------------------------------------------------------------------------------------
static Color4 s_Color4;
static Vector3 s_Vector3;
// --------------------------------------------------------------------------------------------
static SQUint32 s_ColorR, s_ColorG, s_ColorB, s_ColorA;
public:
/* --------------------------------------------------------------------------------------------
* Import the constructors, destructors and assignment operators from the base class.
*/
using RefType::Reference;
/* --------------------------------------------------------------------------------------------
* See if the referenced checkpoint instance is streamed for the specified player.
*/
bool IsStreamedFor(const Reference< CPlayer > & player) const noexcept;
/* --------------------------------------------------------------------------------------------
* Retrieve the world in which the referenced checkpoint instance exists.
*/
SQInt32 GetWorld() const noexcept;
/* --------------------------------------------------------------------------------------------
* Change the world in which the referenced checkpoint instance exists.
*/
void SetWorld(SQInt32 world) const noexcept;
/* --------------------------------------------------------------------------------------------
* Retrieve the color of the referenced checkpoint instance.
*/
const Color4 & GetColor() const noexcept;
/* --------------------------------------------------------------------------------------------
* Change the color of the referenced checkpoint instance.
*/
void SetColor(const Color4 & col) const noexcept;
/* --------------------------------------------------------------------------------------------
* Change the color of the referenced checkpoint instance.
*/
void SetColorEx(Uint8 r, Uint8 g, Uint8 b, Uint8 a) const noexcept;
/* --------------------------------------------------------------------------------------------
* Retrieve the position of the referenced checkpoint instance.
*/
const Vector3 & GetPosition() const noexcept;
/* --------------------------------------------------------------------------------------------
* Change the position of the referenced checkpoint instance.
*/
void SetPosition(const Vector3 & pos) const noexcept;
/* --------------------------------------------------------------------------------------------
* Change the position of the referenced checkpoint instance.
*/
void SetPositionEx(SQFloat x, SQFloat y, SQFloat z) const noexcept;
/* --------------------------------------------------------------------------------------------
* Retrieve the radius of the referenced checkpoint instance.
*/
SQFloat GetRadius() const noexcept;
/* --------------------------------------------------------------------------------------------
* Change the radius of the referenced checkpoint instance.
*/
void SetRadius(SQFloat radius) const noexcept;
/* --------------------------------------------------------------------------------------------
* Retrieve the owner of the referenced checkpoint instance.
*/
Reference< CPlayer > GetOwner() const noexcept;
/* --------------------------------------------------------------------------------------------
* Retrieve the owner identifier of the referenced checkpoint instance.
*/
SQInt32 GetOwnerID() const noexcept;
};
} // Namespace:: SqMod