2015-11-11 07:57:34 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-09-30 02:56:11 +02:00
|
|
|
#include "Entity/Pickup.hpp"
|
2016-02-20 23:25:00 +01:00
|
|
|
#include "Entity/Player.hpp"
|
|
|
|
#include "Base/Vector3.hpp"
|
2015-11-01 00:32:16 +01:00
|
|
|
#include "Core.hpp"
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
namespace SqMod {
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
Vector3 CPickup::s_Vector3;
|
2015-10-29 21:11:00 +01:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-03-10 04:57:13 +01:00
|
|
|
const Int32 CPickup::Max = SQMOD_PICKUP_POOL;
|
2015-10-29 21:11:00 +01:00
|
|
|
|
2015-11-01 00:32:16 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-03-10 04:57:13 +01:00
|
|
|
SQInteger CPickup::Typename(HSQUIRRELVM vm)
|
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
static const SQChar name[] = _SC("SqPickup");
|
2016-03-10 04:57:13 +01:00
|
|
|
sq_pushstring(vm, name, sizeof(name));
|
|
|
|
return 1;
|
|
|
|
}
|
2016-02-20 23:25:00 +01:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
CPickup::CPickup(Int32 id)
|
|
|
|
: m_ID(VALID_ENTITYGETEX(id, SQMOD_PICKUP_POOL))
|
2016-03-10 04:57:13 +01:00
|
|
|
, m_Tag(ToStrF("%d", id))
|
2015-11-01 00:32:16 +01:00
|
|
|
{
|
|
|
|
/* ... */
|
|
|
|
}
|
|
|
|
|
2015-10-29 21:11:00 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
CPickup::~CPickup()
|
2015-10-29 21:11:00 +01:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
/* ... */
|
2015-10-29 21:11:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
Int32 CPickup::Cmp(const CPickup & o) const
|
2015-10-29 21:11:00 +01:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
if (m_ID == o.m_ID)
|
2016-05-22 05:20:38 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return 0;
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
2016-02-20 23:25:00 +01:00
|
|
|
else if (m_ID > o.m_ID)
|
2016-05-22 05:20:38 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return 1;
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
2015-10-29 21:11:00 +01:00
|
|
|
else
|
2016-05-22 05:20:38 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return -1;
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
2016-02-20 23:25:00 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
const String & CPickup::ToString() const
|
2016-02-20 23:25:00 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
return m_Tag;
|
2015-10-29 21:11:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-03-10 04:57:13 +01:00
|
|
|
const String & CPickup::GetTag() const
|
2015-10-29 21:11:00 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
return m_Tag;
|
2016-02-20 23:25:00 +01:00
|
|
|
}
|
2015-10-29 21:11:00 +01:00
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
void CPickup::SetTag(CSStr tag)
|
|
|
|
{
|
|
|
|
m_Tag.assign(tag);
|
2015-10-29 21:11:00 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
Object & CPickup::GetData()
|
2015-10-29 21:11:00 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Return the requested information
|
|
|
|
return m_Data;
|
2016-02-20 23:25:00 +01:00
|
|
|
}
|
2015-10-29 21:11:00 +01:00
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
void CPickup::SetData(Object & data)
|
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Apply the specified value
|
|
|
|
m_Data = data;
|
2015-10-29 21:11:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
bool CPickup::Destroy(Int32 header, Object & payload)
|
2015-10-29 21:11:00 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Perform the requested operation
|
2016-05-22 05:20:38 +02:00
|
|
|
return Core::Get().DelPickup(m_ID, header, payload);
|
2015-10-29 21:11:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-03-10 04:57:13 +01:00
|
|
|
void CPickup::BindEvent(Int32 evid, Object & env, Function & func) const
|
2015-10-29 21:11:00 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Obtain the function instance called for this event
|
2016-05-22 05:20:38 +02:00
|
|
|
Function & event = Core::Get().GetPickupEvent(m_ID, evid);
|
2016-03-10 04:57:13 +01:00
|
|
|
// Is the specified callback function null?
|
2016-02-20 23:25:00 +01:00
|
|
|
if (func.IsNull())
|
2016-03-12 21:51:44 +01:00
|
|
|
{
|
2016-05-24 20:36:49 +02:00
|
|
|
event.ReleaseGently(); // Then release the current callback
|
2016-03-12 21:51:44 +01:00
|
|
|
}
|
2016-05-24 06:29:14 +02:00
|
|
|
// Does this function need a custom environment?
|
|
|
|
else if (env.IsNull())
|
|
|
|
{
|
|
|
|
event = func;
|
|
|
|
}
|
2016-03-10 04:57:13 +01:00
|
|
|
// Assign the specified environment and function
|
2015-10-29 21:11:00 +01:00
|
|
|
else
|
2016-03-12 21:51:44 +01:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
event = Function(env.GetVM(), env, func.GetFunc());
|
2016-03-12 21:51:44 +01:00
|
|
|
}
|
2015-10-29 21:11:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
bool CPickup::IsStreamedFor(CPlayer & player) const
|
2015-10-29 21:11:00 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Is the specified player even valid?
|
2016-02-20 23:25:00 +01:00
|
|
|
if (!player.IsActive())
|
2016-03-12 21:51:44 +01:00
|
|
|
{
|
2016-03-21 21:37:58 +01:00
|
|
|
STHROWF("Invalid player argument: null");
|
2016-03-12 21:51:44 +01:00
|
|
|
}
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Return the requested information
|
|
|
|
return _Func->IsPickupStreamedForPlayer(m_ID, player.GetID());
|
2016-02-20 23:25:00 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
Int32 CPickup::GetWorld() const
|
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Return the requested information
|
|
|
|
return _Func->GetPickupWorld(m_ID);
|
2016-02-20 23:25:00 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
void CPickup::SetWorld(Int32 world) const
|
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Perform the requested operation
|
|
|
|
_Func->SetPickupWorld(m_ID, world);
|
2016-02-20 23:25:00 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
Int32 CPickup::GetAlpha() const
|
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Return the requested information
|
2016-05-22 05:20:38 +02:00
|
|
|
return _Func->GetPickupAlpha(m_ID);
|
2016-02-20 23:25:00 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
void CPickup::SetAlpha(Int32 alpha) const
|
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Perform the requested operation
|
2016-05-22 05:20:38 +02:00
|
|
|
_Func->SetPickupAlpha(m_ID, alpha);
|
2015-10-29 21:11:00 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
bool CPickup::GetAutomatic() const
|
2015-10-29 21:11:00 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Return the requested information
|
2016-05-22 05:20:38 +02:00
|
|
|
return _Func->IsPickupAutomatic(m_ID);
|
2015-10-29 21:11:00 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
void CPickup::SetAutomatic(bool toggle) const
|
2015-10-29 21:11:00 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Perform the requested operation
|
2016-05-22 05:20:38 +02:00
|
|
|
_Func->SetPickupIsAutomatic(m_ID, toggle);
|
2015-10-29 21:11:00 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
Int32 CPickup::GetAutoTimer() const
|
2015-10-29 21:11:00 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Return the requested information
|
|
|
|
return _Func->GetPickupAutoTimer(m_ID);
|
2015-10-29 21:11:00 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
void CPickup::SetAutoTimer(Int32 timer) const
|
2015-10-29 21:11:00 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Perform the requested operation
|
|
|
|
_Func->SetPickupAutoTimer(m_ID, timer);
|
2015-10-29 21:11:00 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
void CPickup::Refresh() const
|
2015-10-29 21:11:00 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Perform the requested operation
|
2016-05-22 05:20:38 +02:00
|
|
|
_Func->RefreshPickup(m_ID);
|
2015-10-29 21:11:00 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
const Vector3 & CPickup::GetPosition()
|
2015-10-29 21:11:00 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Clear previous position information, if any
|
2015-10-29 21:11:00 +01:00
|
|
|
s_Vector3.Clear();
|
2016-03-10 04:57:13 +01:00
|
|
|
// Query the server for the position values
|
2016-05-22 05:20:38 +02:00
|
|
|
_Func->GetPickupPosition(m_ID, &s_Vector3.x, &s_Vector3.y, &s_Vector3.z);
|
2016-03-10 04:57:13 +01:00
|
|
|
// Return the requested information
|
2015-10-29 21:11:00 +01:00
|
|
|
return s_Vector3;
|
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
void CPickup::SetPosition(const Vector3 & pos) const
|
2015-10-29 21:11:00 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Perform the requested operation
|
2016-05-22 05:20:38 +02:00
|
|
|
_Func->SetPickupPosition(m_ID, pos.x, pos.y, pos.z);
|
2015-10-29 21:11:00 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
void CPickup::SetPositionEx(Float32 x, Float32 y, Float32 z) const
|
2015-10-29 21:11:00 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Perform the requested operation
|
2016-05-22 05:20:38 +02:00
|
|
|
_Func->SetPickupPosition(m_ID, x, y, z);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Int32 CPickup::GetModel() const
|
|
|
|
{
|
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Return the requested information
|
|
|
|
return _Func->GetPickupModel(m_ID);
|
2015-10-29 21:11:00 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
Int32 CPickup::GetQuantity() const
|
2015-10-29 21:11:00 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Return the requested information
|
2016-05-22 05:20:38 +02:00
|
|
|
return _Func->GetPickupQuantity(m_ID);
|
2015-11-01 00:32:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-05-22 05:20:38 +02:00
|
|
|
Float32 CPickup::GetPositionX() const
|
2015-11-01 00:32:16 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Clear previous position information, if any
|
2016-02-20 23:25:00 +01:00
|
|
|
s_Vector3.x = 0;
|
2016-03-10 04:57:13 +01:00
|
|
|
// Query the server for the requested component value
|
2016-05-22 05:20:38 +02:00
|
|
|
_Func->GetPickupPosition(m_ID, &s_Vector3.x, NULL, NULL);
|
2016-03-10 04:57:13 +01:00
|
|
|
// Return the requested information
|
2016-02-20 23:25:00 +01:00
|
|
|
return s_Vector3.x;
|
2015-11-01 00:32:16 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-05-22 05:20:38 +02:00
|
|
|
Float32 CPickup::GetPositionY() const
|
2015-11-01 00:32:16 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Clear previous position information, if any
|
2016-02-20 23:25:00 +01:00
|
|
|
s_Vector3.y = 0;
|
2016-03-10 04:57:13 +01:00
|
|
|
// Query the server for the requested component value
|
2016-05-22 05:20:38 +02:00
|
|
|
_Func->GetPickupPosition(m_ID, NULL, &s_Vector3.y, NULL);
|
2016-03-10 04:57:13 +01:00
|
|
|
// Return the requested information
|
2016-02-20 23:25:00 +01:00
|
|
|
return s_Vector3.y;
|
2015-11-01 00:32:16 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-05-22 05:20:38 +02:00
|
|
|
Float32 CPickup::GetPositionZ() const
|
2015-11-01 00:32:16 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Clear previous position information, if any
|
2016-02-20 23:25:00 +01:00
|
|
|
s_Vector3.z = 0;
|
2016-03-10 04:57:13 +01:00
|
|
|
// Query the server for the requested component value
|
2016-05-22 05:20:38 +02:00
|
|
|
_Func->GetPickupPosition(m_ID, NULL, NULL, &s_Vector3.z);
|
2016-03-10 04:57:13 +01:00
|
|
|
// Return the requested information
|
2016-02-20 23:25:00 +01:00
|
|
|
return s_Vector3.z;
|
2015-11-01 00:32:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-05-22 05:20:38 +02:00
|
|
|
void CPickup::SetPositionX(Float32 x) const
|
2015-11-01 00:32:16 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Retrieve the current values for unchanged components
|
2016-05-22 05:20:38 +02:00
|
|
|
_Func->GetPickupPosition(m_ID, NULL, &s_Vector3.y, &s_Vector3.z);
|
2016-03-10 04:57:13 +01:00
|
|
|
// Perform the requested operation
|
2016-05-22 05:20:38 +02:00
|
|
|
_Func->SetPickupPosition(m_ID, x, s_Vector3.y, s_Vector3.z);
|
2015-11-01 00:32:16 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-05-22 05:20:38 +02:00
|
|
|
void CPickup::SetPositionY(Float32 y) const
|
2015-11-01 00:32:16 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Retrieve the current values for unchanged components
|
2016-05-22 05:20:38 +02:00
|
|
|
_Func->GetPickupPosition(m_ID, &s_Vector3.x, NULL, &s_Vector3.z);
|
2016-03-10 04:57:13 +01:00
|
|
|
// Perform the requested operation
|
2016-05-22 05:20:38 +02:00
|
|
|
_Func->SetPickupPosition(m_ID, s_Vector3.x, y, s_Vector3.z);
|
2015-11-01 00:32:16 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-05-22 05:20:38 +02:00
|
|
|
void CPickup::SetPositionZ(Float32 z) const
|
2015-11-01 00:32:16 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Retrieve the current values for unchanged components
|
2016-05-22 05:20:38 +02:00
|
|
|
_Func->GetPickupPosition(m_ID, &s_Vector3.x, &s_Vector3.y, NULL);
|
2016-03-10 04:57:13 +01:00
|
|
|
// Perform the requested operation
|
2016-05-22 05:20:38 +02:00
|
|
|
_Func->SetPickupPosition(m_ID, s_Vector3.z, s_Vector3.y, z);
|
2015-11-01 00:32:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-03-10 04:57:13 +01:00
|
|
|
static Object & Pickup_CreateEx(Int32 model, Int32 world, Int32 quantity,
|
2016-02-20 23:25:00 +01:00
|
|
|
Float32 x, Float32 y, Float32 z, Int32 alpha, bool automatic)
|
2015-11-01 00:32:16 +01:00
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
return Core::Get().NewPickup(model, world, quantity, x, y, z, alpha, automatic,
|
2016-02-20 23:25:00 +01:00
|
|
|
SQMOD_CREATE_DEFAULT, NullObject());
|
2015-11-01 00:32:16 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
static Object & Pickup_CreateEx(Int32 model, Int32 world, Int32 quantity,
|
2016-02-20 23:25:00 +01:00
|
|
|
Float32 x, Float32 y, Float32 z, Int32 alpha, bool automatic,
|
|
|
|
Int32 header, Object & payload)
|
2015-11-01 00:32:16 +01:00
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
return Core::Get().NewPickup(model, world, quantity, x, y, z, alpha, automatic, header, payload);
|
2015-11-01 00:32:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-03-10 04:57:13 +01:00
|
|
|
static Object & Pickup_Create(Int32 model, Int32 world, Int32 quantity, const Vector3 & pos,
|
2016-02-20 23:25:00 +01:00
|
|
|
Int32 alpha, bool automatic)
|
2015-11-01 00:32:16 +01:00
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
return Core::Get().NewPickup(model, world, quantity, pos.x, pos.y, pos.z, alpha, automatic,
|
2016-02-20 23:25:00 +01:00
|
|
|
SQMOD_CREATE_DEFAULT, NullObject());
|
2015-11-01 00:32:16 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
static Object & Pickup_Create(Int32 model, Int32 world, Int32 quantity, const Vector3 & pos,
|
2016-02-20 23:25:00 +01:00
|
|
|
Int32 alpha, bool automatic, Int32 header, Object & payload)
|
2015-11-01 00:32:16 +01:00
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
return Core::Get().NewPickup(model, world, quantity, pos.x, pos.y, pos.z, alpha, automatic,
|
2015-11-01 00:32:16 +01:00
|
|
|
header, payload);
|
|
|
|
}
|
|
|
|
|
2016-03-10 05:18:39 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static const Object & Pickup_FindByID(Int32 id)
|
|
|
|
{
|
|
|
|
// Perform a range check on the specified identifier
|
|
|
|
if (INVALID_ENTITYEX(id, SQMOD_PICKUP_POOL))
|
2016-03-12 21:51:44 +01:00
|
|
|
{
|
2016-03-21 21:37:58 +01:00
|
|
|
STHROWF("The specified pickup identifier is invalid: %d", id);
|
2016-03-12 21:51:44 +01:00
|
|
|
}
|
2016-03-10 05:18:39 +01:00
|
|
|
// Obtain the ends of the entity pool
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Pickups::const_iterator itr = Core::Get().GetPickups().cbegin();
|
|
|
|
Core::Pickups::const_iterator end = Core::Get().GetPickups().cend();
|
2016-03-10 05:18:39 +01:00
|
|
|
// Process each entity in the pool
|
|
|
|
for (; itr != end; ++itr)
|
|
|
|
{
|
|
|
|
// Does the identifier match the specified one?
|
|
|
|
if (itr->mID == id)
|
2016-03-12 21:51:44 +01:00
|
|
|
{
|
2016-03-10 05:18:39 +01:00
|
|
|
return itr->mObj; // Stop searching and return this entity
|
2016-03-12 21:51:44 +01:00
|
|
|
}
|
2016-03-10 05:18:39 +01:00
|
|
|
}
|
|
|
|
// Unable to locate a pickup matching the specified identifier
|
|
|
|
return NullObject();
|
|
|
|
}
|
|
|
|
|
2016-03-26 17:17:05 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-03-10 05:18:39 +01:00
|
|
|
static const Object & Pickup_FindByTag(CSStr tag)
|
|
|
|
{
|
|
|
|
// Perform a validity check on the specified tag
|
2016-03-12 21:51:44 +01:00
|
|
|
if (!tag || *tag == '0')
|
|
|
|
{
|
2016-03-21 21:37:58 +01:00
|
|
|
STHROWF("The specified pickup tag is invalid: null/empty");
|
2016-03-12 21:51:44 +01:00
|
|
|
}
|
2016-03-10 05:18:39 +01:00
|
|
|
// Obtain the ends of the entity pool
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Pickups::const_iterator itr = Core::Get().GetPickups().cbegin();
|
|
|
|
Core::Pickups::const_iterator end = Core::Get().GetPickups().cend();
|
2016-03-10 05:18:39 +01:00
|
|
|
// Process each entity in the pool
|
|
|
|
for (; itr != end; ++itr)
|
|
|
|
{
|
|
|
|
// Does this entity even exist and does the tag match the specified one?
|
|
|
|
if (itr->mInst != nullptr && itr->mInst->GetTag().compare(tag) == 0)
|
2016-03-12 21:51:44 +01:00
|
|
|
{
|
2016-03-10 05:18:39 +01:00
|
|
|
return itr->mObj; // Stop searching and return this entity
|
2016-03-12 21:51:44 +01:00
|
|
|
}
|
2016-03-10 05:18:39 +01:00
|
|
|
}
|
|
|
|
// Unable to locate a pickup matching the specified tag
|
|
|
|
return NullObject();
|
|
|
|
}
|
|
|
|
|
2016-03-26 17:17:05 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static Array Pickup_FindActive()
|
|
|
|
{
|
|
|
|
// Remember the initial stack size
|
|
|
|
StackGuard sg;
|
|
|
|
// Obtain the ends of the entity pool
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Pickups::const_iterator itr = Core::Get().GetPickups().cbegin();
|
|
|
|
Core::Pickups::const_iterator end = Core::Get().GetPickups().cend();
|
2016-03-26 17:17:05 +01:00
|
|
|
// Allocate an empty array on the stack
|
|
|
|
sq_newarray(DefaultVM::Get(), 0);
|
|
|
|
// Process each entity in the pool
|
|
|
|
for (; itr != end; ++itr)
|
|
|
|
{
|
|
|
|
// Is this entity instance active?
|
|
|
|
if (VALID_ENTITY(itr->mID))
|
|
|
|
{
|
|
|
|
// Push the script object on the stack
|
|
|
|
sq_pushobject(DefaultVM::Get(), (HSQOBJECT &)((*itr).mObj));
|
|
|
|
// Append the object at the back of the array
|
|
|
|
if (SQ_FAILED(sq_arrayappend(DefaultVM::Get(), -1)))
|
|
|
|
{
|
|
|
|
STHROWF("Unable to append entity instance to the list");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Return the array at the top of the stack
|
|
|
|
return Var< Array >(DefaultVM::Get(), -1).value;
|
|
|
|
}
|
|
|
|
|
2015-10-29 21:11:00 +01:00
|
|
|
// ================================================================================================
|
2016-02-20 23:25:00 +01:00
|
|
|
void Register_CPickup(HSQUIRRELVM vm)
|
|
|
|
{
|
|
|
|
RootTable(vm).Bind(_SC("SqPickup"),
|
|
|
|
Class< CPickup, NoConstructor< CPickup > >(vm, _SC("SqPickup"))
|
2016-06-03 20:26:19 +02:00
|
|
|
// Meta-methods
|
2016-02-20 23:25:00 +01:00
|
|
|
.Func(_SC("_cmp"), &CPickup::Cmp)
|
2016-03-10 04:57:13 +01:00
|
|
|
.SquirrelFunc(_SC("_typename"), &CPickup::Typename)
|
2016-02-20 23:25:00 +01:00
|
|
|
.Func(_SC("_tostring"), &CPickup::ToString)
|
2016-03-10 05:18:39 +01:00
|
|
|
// Static Values
|
2016-03-10 04:57:13 +01:00
|
|
|
.SetStaticValue(_SC("MaxID"), CPickup::Max)
|
|
|
|
// Core Properties
|
2016-02-20 23:25:00 +01:00
|
|
|
.Prop(_SC("ID"), &CPickup::GetID)
|
|
|
|
.Prop(_SC("Tag"), &CPickup::GetTag, &CPickup::SetTag)
|
|
|
|
.Prop(_SC("Data"), &CPickup::GetData, &CPickup::SetData)
|
|
|
|
.Prop(_SC("Active"), &CPickup::IsActive)
|
2016-03-10 05:18:39 +01:00
|
|
|
// Core Methods
|
2016-02-20 23:25:00 +01:00
|
|
|
.Func(_SC("Bind"), &CPickup::BindEvent)
|
2016-03-10 04:57:13 +01:00
|
|
|
// Core Overloads
|
2016-02-20 23:25:00 +01:00
|
|
|
.Overload< bool (CPickup::*)(void) >(_SC("Destroy"), &CPickup::Destroy)
|
|
|
|
.Overload< bool (CPickup::*)(Int32) >(_SC("Destroy"), &CPickup::Destroy)
|
|
|
|
.Overload< bool (CPickup::*)(Int32, Object &) >(_SC("Destroy"), &CPickup::Destroy)
|
2016-03-10 04:57:13 +01:00
|
|
|
// Properties
|
2016-02-20 23:25:00 +01:00
|
|
|
.Prop(_SC("Model"), &CPickup::GetModel)
|
|
|
|
.Prop(_SC("World"), &CPickup::GetWorld, &CPickup::SetWorld)
|
|
|
|
.Prop(_SC("Alpha"), &CPickup::GetAlpha, &CPickup::SetAlpha)
|
|
|
|
.Prop(_SC("Auto"), &CPickup::GetAutomatic, &CPickup::SetAutomatic)
|
|
|
|
.Prop(_SC("Automatic"), &CPickup::GetAutomatic, &CPickup::SetAutomatic)
|
|
|
|
.Prop(_SC("Timer"), &CPickup::GetAutoTimer, &CPickup::SetAutoTimer)
|
|
|
|
.Prop(_SC("Autotimer"), &CPickup::GetAutoTimer, &CPickup::SetAutoTimer)
|
|
|
|
.Prop(_SC("Pos"), &CPickup::GetPosition, &CPickup::SetPosition)
|
|
|
|
.Prop(_SC("Position"), &CPickup::GetPosition, &CPickup::SetPosition)
|
|
|
|
.Prop(_SC("Quantity"), &CPickup::GetQuantity)
|
2016-05-22 05:20:38 +02:00
|
|
|
.Prop(_SC("PosX"), &CPickup::GetPositionX, &CPickup::SetPositionX)
|
|
|
|
.Prop(_SC("PosY"), &CPickup::GetPositionY, &CPickup::SetPositionY)
|
|
|
|
.Prop(_SC("PosZ"), &CPickup::GetPositionZ, &CPickup::SetPositionZ)
|
2016-03-10 05:18:39 +01:00
|
|
|
// Member Methods
|
2016-02-20 23:25:00 +01:00
|
|
|
.Func(_SC("StreamedFor"), &CPickup::IsStreamedFor)
|
|
|
|
.Func(_SC("Refresh"), &CPickup::Refresh)
|
|
|
|
.Func(_SC("SetPos"), &CPickup::SetPositionEx)
|
|
|
|
.Func(_SC("SetPosition"), &CPickup::SetPositionEx)
|
2016-03-10 05:18:39 +01:00
|
|
|
// Static Functions
|
|
|
|
.StaticFunc(_SC("FindByID"), &Pickup_FindByID)
|
|
|
|
.StaticFunc(_SC("FindByTag"), &Pickup_FindByTag)
|
2016-03-26 17:17:05 +01:00
|
|
|
.StaticFunc(_SC("FindActive"), &Pickup_FindActive)
|
2016-03-10 04:57:13 +01:00
|
|
|
// Static Overloads
|
|
|
|
.StaticOverload< Object & (*)(Int32, Int32, Int32, Float32, Float32, Float32, Int32, bool) >
|
|
|
|
(_SC("CreateEx"), &Pickup_CreateEx)
|
|
|
|
.StaticOverload< Object & (*)(Int32, Int32, Int32, Float32, Float32, Float32, Int32, bool, Int32, Object &) >
|
|
|
|
(_SC("CreateEx"), &Pickup_CreateEx)
|
|
|
|
.StaticOverload< Object & (*)(Int32, Int32, Int32, const Vector3 &, Int32, bool) >
|
|
|
|
(_SC("Create"), &Pickup_Create)
|
|
|
|
.StaticOverload< Object & (*)(Int32, Int32, Int32, const Vector3 &, Int32, bool, Int32, Object &) >
|
|
|
|
(_SC("Create"), &Pickup_Create)
|
2015-09-30 02:56:11 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-04-14 02:08:06 +02:00
|
|
|
} // Namespace:: SqMod
|