1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-06-16 07:07:13 +02:00

Initial implementation of the area system.

This commit is contained in:
Sandu Liviu Catalin
2017-06-19 04:09:35 +03:00
parent 6504f196bb
commit 2fb58f9fbf
16 changed files with 1507 additions and 4 deletions

View File

@ -6,6 +6,7 @@
#include "Base/Vector3.hpp"
#include "Library/Utils/Buffer.hpp"
#include "Core.hpp"
#include "Areas.hpp"
#include "Tasks.hpp"
// ------------------------------------------------------------------------------------------------
@ -1431,6 +1432,83 @@ LightObj & CPlayer::CreateCheckpoint(Int32 world, bool sphere, const Vector3 & p
color.r, color.g, color.b, color.a, radius, header, payload);
}
// ------------------------------------------------------------------------------------------------
bool CPlayer::GetCollideAreas() const
{
// Validate the managed identifier
Validate();
// Return the requested information
return (Core::Get().GetPlayer(m_ID).mFlags & ENF_AREA_TRACK);
}
void CPlayer::SetCollideAreas(bool toggle) const
{
// Validate the managed identifier
Validate();
// Perform the requested operation
if (toggle)
{
Core::Get().GetPlayer(m_ID).mFlags |= ENF_AREA_TRACK;
}
else
{
// Obtain the actual entity instance
auto & inst = Core::Get().GetPlayer(m_ID);
// Is this option even enabled?
if (!(inst.mFlags & ENF_AREA_TRACK))
{
return; // Not enabled to begin with
}
// Disable the option
inst.mFlags ^= ENF_AREA_TRACK;
// Clear current areas
inst.mAreas.clear();
}
}
void CPlayer::SetAreasCollide(bool toggle) const
{
// Validate the managed identifier
Validate();
// Perform the requested operation
if (toggle)
{
Core::Get().GetPlayer(m_ID).mFlags |= ENF_AREA_TRACK;
}
else
{
// Obtain the actual entity instance
auto & inst = Core::Get().GetPlayer(m_ID);
// Is this option even enabled?
if (!(inst.mFlags & ENF_AREA_TRACK))
{
return; // Not enabled to begin with
}
// Disable the option
inst.mFlags ^= ENF_AREA_TRACK;
// Is the player currently in any areas?
if (inst.mAreas.empty())
{
return; // Nothing to test
}
Vector3 pos;
// Obtain the current position of this instance
_Func->GetPlayerPosition(m_ID, &pos.x, &pos.y, &pos.z);
// Do a final check to see if the player left any area
for (auto & ap : inst.mAreas)
{
// Is the player still in this area?
if (!ap.first->TestEx(pos.x, pos.y))
{
Core::Get().EmitPlayerLeaveArea(m_ID, ap.second); // Emit the script event
}
}
// Clear current areas
inst.mAreas.clear();
}
}
// ------------------------------------------------------------------------------------------------
Int32 CPlayer::GetAuthority() const
{
@ -2423,6 +2501,7 @@ void Register_CPlayer(HSQUIRRELVM vm)
.Prop(_SC("TouchedObject"), &CPlayer::StandingOnObject)
.Prop(_SC("Away"), &CPlayer::IsAway)
.Prop(_SC("Spec"), &CPlayer::GetSpectator, &CPlayer::SetSpectator)
.Prop(_SC("CollideAreas"), &CPlayer::GetCollideAreas, &CPlayer::SetCollideAreas)
.Prop(_SC("Authority"), &CPlayer::GetAuthority, &CPlayer::SetAuthority)
.Prop(_SC("TrackPosition"), &CPlayer::GetTrackPosition, &CPlayer::SetTrackPosition)
.Prop(_SC("TrackHeading"), &CPlayer::GetTrackHeading, &CPlayer::SetTrackHeading)
@ -2472,6 +2551,7 @@ void Register_CPlayer(HSQUIRRELVM vm)
.Func(_SC("Spectate"), &CPlayer::SetSpectator)
.Func(_SC("Redirect"), &CPlayer::Redirect)
.Func(_SC("PlaySound"), &CPlayer::PlaySound)
.Func(_SC("AreasCollide"), &CPlayer::SetAreasCollide)
.Func(_SC("GetMsgPrefix"), &CPlayer::GetMessagePrefix)
.FmtFunc(_SC("SetMsgPrefix"), &CPlayer::SetMessagePrefix)
.Func(_SC("SetTrackPosition"), &CPlayer::SetTrackPositionEx)

View File

@ -765,6 +765,21 @@ public:
LightObj & CreateCheckpoint(Int32 world, bool sphere, const Vector3 & pos, const Color4 & color,
Float32 radius, Int32 header, LightObj & payload) const;
/* --------------------------------------------------------------------------------------------
* See whether the managed player entity collides with user defined areas.
*/
bool GetCollideAreas() const;
/* --------------------------------------------------------------------------------------------
* Set whether the managed player entity can collide with user defined areas.
*/
void SetCollideAreas(bool toggle) const;
/* --------------------------------------------------------------------------------------------
* Set whether the managed player entity can collide with user defined areas (with last test).
*/
void SetAreasCollide(bool toggle) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the authority level of the managed player entity.
*/

View File

@ -5,6 +5,7 @@
#include "Base/Vector2.hpp"
#include "Base/Vector3.hpp"
#include "Core.hpp"
#include "Areas.hpp"
#include "Tasks.hpp"
// ------------------------------------------------------------------------------------------------
@ -1119,6 +1120,83 @@ bool CVehicle::Embark(CPlayer & player, Int32 slot, bool allocate, bool warp) co
!= vcmpErrorRequestDenied);
}
// ------------------------------------------------------------------------------------------------
bool CVehicle::GetCollideAreas() const
{
// Validate the managed identifier
Validate();
// Return the requested information
return (Core::Get().GetVehicle(m_ID).mFlags & ENF_AREA_TRACK);
}
void CVehicle::SetCollideAreas(bool toggle) const
{
// Validate the managed identifier
Validate();
// Perform the requested operation
if (toggle)
{
Core::Get().GetVehicle(m_ID).mFlags |= ENF_AREA_TRACK;
}
else
{
// Obtain the actual entity instance
auto & inst = Core::Get().GetVehicle(m_ID);
// Is this option even enabled?
if (!(inst.mFlags & ENF_AREA_TRACK))
{
return; // Not enabled to begin with
}
// Disable the option
inst.mFlags ^= ENF_AREA_TRACK;
// Clear current areas
inst.mAreas.clear();
}
}
void CVehicle::SetAreasCollide(bool toggle) const
{
// Validate the managed identifier
Validate();
// Perform the requested operation
if (toggle)
{
Core::Get().GetVehicle(m_ID).mFlags |= ENF_AREA_TRACK;
}
else
{
// Obtain the actual entity instance
auto & inst = Core::Get().GetVehicle(m_ID);
// Is this option even enabled?
if (!(inst.mFlags & ENF_AREA_TRACK))
{
return; // Not enabled to begin with
}
// Disable the option
inst.mFlags ^= ENF_AREA_TRACK;
// Is the vehicle currently in any areas?
if (inst.mAreas.empty())
{
return; // Nothing to test
}
Vector3 pos;
// Obtain the current position of this instance
_Func->GetVehiclePosition(m_ID, &pos.x, &pos.y, &pos.z);
// Do a final check to see if the vehicle left any area
for (auto & ap : inst.mAreas)
{
// Is the vehicle still in this area?
if (!ap.first->TestEx(pos.x, pos.y))
{
Core::Get().EmitVehicleLeaveArea(m_ID, ap.second); // Emit the script event
}
}
// Clear current areas
inst.mAreas.clear();
}
}
// ------------------------------------------------------------------------------------------------
SQInteger CVehicle::GetTrackPosition() const
{
@ -1820,6 +1898,7 @@ void Register_CVehicle(HSQUIRRELVM vm)
.Prop(_SC("HorizontalTurretRotation"), &CVehicle::GetHorizontalTurretRotation)
.Prop(_SC("VerTurretRotation"), &CVehicle::GetVerticalTurretRotation)
.Prop(_SC("VerticalTurretRotation"), &CVehicle::GetVerticalTurretRotation)
.Prop(_SC("CollideAreas"), &CVehicle::GetCollideAreas, &CVehicle::SetCollideAreas)
.Prop(_SC("TrackPosition"), &CVehicle::GetTrackPosition, &CVehicle::SetTrackPosition)
.Prop(_SC("TrackRotation"), &CVehicle::GetTrackRotation, &CVehicle::SetTrackRotation)
.Prop(_SC("LastPrimaryColor"), &CVehicle::GetLastPrimaryColor)
@ -1885,6 +1964,7 @@ void Register_CVehicle(HSQUIRRELVM vm)
.Func(_SC("SetHandlingRule"), &CVehicle::SetHandlingRule)
.Func(_SC("ResetHandlingRule"), &CVehicle::ResetHandlingRule)
.Func(_SC("ResetHandlings"), &CVehicle::ResetHandlings)
.Func(_SC("AreasCollide"), &CVehicle::SetAreasCollide)
// Member Overloads
.Overload< void (CVehicle::*)(const Vector3 &, bool) const >
(_SC("SetPos"), &CVehicle::SetPositionEx)

View File

@ -612,6 +612,21 @@ public:
*/
bool Embark(CPlayer & player, Int32 slot, bool allocate, bool warp) const;
/* --------------------------------------------------------------------------------------------
* See whether the managed vehicle entity collides with user defined areas.
*/
bool GetCollideAreas() const;
/* --------------------------------------------------------------------------------------------
* Set whether the managed vehicle entity can collide with user defined areas.
*/
void SetCollideAreas(bool toggle) const;
/* --------------------------------------------------------------------------------------------
* Set whether the managed vehicle entity can collide with user defined areas (with last test).
*/
void SetAreasCollide(bool toggle) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the amount of tracked position changes for the managed vehicle entity.
*/