mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2024-11-08 00:37:15 +01:00
Implement simple distance tracking for player and vehicle entities.
Doesn't differentiate from in-air and on-ground. Just sums up the distance from last position on each position update.
This commit is contained in:
parent
f2be86a65e
commit
4c1030c76e
@ -422,6 +422,7 @@ protected:
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
AreaList mAreas{}; // Areas the player is currently in.
|
||||
Float64 mDistance; // Distance traveled while tracking was enabled.
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
SQInteger mTrackPosition{0}; // The number of times to track position changes.
|
||||
@ -582,6 +583,7 @@ protected:
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
AreaList mAreas{}; // Areas the vehicle is currently in.
|
||||
Float64 mDistance; // Distance traveled while tracking was enabled.
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
SQInteger mTrackPosition{0}; // The number of times to track position changes.
|
||||
|
@ -1481,7 +1481,12 @@ void Core::EmitPlayerUpdate(Int32 player_id, vcmpPlayerUpdate update_type)
|
||||
// Now emit the event
|
||||
EmitPlayerPosition(player_id);
|
||||
}
|
||||
// Should we check for area collision
|
||||
// Should we check for distance traveled?
|
||||
if (inst.mFlags & ENF_DIST_TRACK)
|
||||
{
|
||||
inst.mDistance += inst.mLastPosition.GetDistanceTo(pos);
|
||||
}
|
||||
// Should we check for area collision?
|
||||
if (inst.mFlags & ENF_AREA_TRACK)
|
||||
{
|
||||
// Eliminate existing areas first, if the player is not in them anymore
|
||||
@ -1716,7 +1721,12 @@ void Core::EmitVehicleUpdate(Int32 vehicle_id, vcmpVehicleUpdate update_type)
|
||||
Vector3 pos;
|
||||
// Retrieve the current vehicle position
|
||||
_Func->GetVehiclePosition(vehicle_id, &pos.x, &pos.y, &pos.z);
|
||||
// Should we check for area collision
|
||||
// Should we check for distance traveled?
|
||||
if (inst.mFlags & ENF_DIST_TRACK)
|
||||
{
|
||||
inst.mDistance += inst.mLastPosition.GetDistanceTo(pos);
|
||||
}
|
||||
// Should we check for area collision?
|
||||
if (inst.mFlags & ENF_AREA_TRACK)
|
||||
{
|
||||
// Eliminate existing areas first, if the vehicle is not in them anymore
|
||||
|
@ -344,6 +344,7 @@ void Core::PlayerInst::ResetInstance()
|
||||
mID = -1;
|
||||
mFlags = ENF_DEFAULT;
|
||||
mAreas.clear();
|
||||
mDistance = 0;
|
||||
mTrackPosition = 0;
|
||||
mTrackHeading = 0;
|
||||
mTrackPositionHeader = 0;
|
||||
@ -364,6 +365,7 @@ void Core::VehicleInst::ResetInstance()
|
||||
mID = -1;
|
||||
mFlags = ENF_DEFAULT;
|
||||
mAreas.clear();
|
||||
mDistance = 0;
|
||||
mTrackPosition = 0;
|
||||
mTrackRotation = 0;
|
||||
mLastPrimaryColor = -1;
|
||||
|
@ -1780,6 +1780,49 @@ const Vector3 & CPlayer::GetLastPosition() const
|
||||
return Core::Get().GetPlayer(m_ID).mLastPosition;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQFloat CPlayer::GetDistance() const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Return the requested information
|
||||
return static_cast< SQFloat >(Core::Get().GetPlayer(m_ID).mDistance);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CPlayer::SetDistance(SQFloat distance) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Assign the requested information
|
||||
Core::Get().GetPlayer(m_ID).mDistance = static_cast< Float64 >(distance);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool CPlayer::GetTrackDistance() const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Return the requested information
|
||||
return static_cast< bool >(Core::Get().GetPlayer(m_ID).mFlags & ENF_DIST_TRACK);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CPlayer::SetTrackDistance(bool toggle) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Assign the requested information
|
||||
if (toggle)
|
||||
{
|
||||
Core::Get().GetPlayer(m_ID).mFlags |= ENF_DIST_TRACK;
|
||||
}
|
||||
else
|
||||
{
|
||||
Core::Get().GetPlayer(m_ID).mFlags ^= ENF_DIST_TRACK;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CPlayer::StartStream()
|
||||
{
|
||||
@ -2796,6 +2839,8 @@ void Register_CPlayer(HSQUIRRELVM vm)
|
||||
.Prop(_SC("LastArmour"), &CPlayer::GetLastArmour)
|
||||
.Prop(_SC("LastHeading"), &CPlayer::GetLastHeading)
|
||||
.Prop(_SC("LastPosition"), &CPlayer::GetLastPosition)
|
||||
.Prop(_SC("Distance"), &CPlayer::GetDistance, &CPlayer::SetDistance)
|
||||
.Prop(_SC("TrackDistance"), &CPlayer::GetTrackDistance, &CPlayer::SetTrackDistance)
|
||||
.Prop(_SC("BufferCursor"), &CPlayer::GetBufferCursor, &CPlayer::SetBufferCursor)
|
||||
.Prop(_SC("BufferCapacity"), &CPlayer::GetBufferCapacity)
|
||||
.Prop(_SC("PosX"), &CPlayer::GetPositionX, &CPlayer::SetPositionX)
|
||||
|
@ -925,6 +925,26 @@ public:
|
||||
*/
|
||||
const Vector3 & GetLastPosition() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the distance traveled by the managed player entity while tracking was enabled.
|
||||
*/
|
||||
SQFloat GetDistance() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the distance traveled by the managed player entity.
|
||||
*/
|
||||
void SetDistance(SQFloat distance) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether distance tracking is enabled for the managed player entity.
|
||||
*/
|
||||
bool GetTrackDistance() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set whether distance tracking is enabled for the managed player entity.
|
||||
*/
|
||||
void SetTrackDistance(bool toggle) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Start a new stream with the default size.
|
||||
*/
|
||||
|
@ -1349,6 +1349,49 @@ const Quaternion & CVehicle::GetLastRotation() const
|
||||
return Core::Get().GetVehicle(m_ID).mLastRotation;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQFloat CVehicle::GetDistance() const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Return the requested information
|
||||
return static_cast< SQFloat >(Core::Get().GetVehicle(m_ID).mDistance);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CVehicle::SetDistance(SQFloat distance) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Assign the requested information
|
||||
Core::Get().GetVehicle(m_ID).mDistance = static_cast< Float64 >(distance);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool CVehicle::GetTrackDistance() const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Return the requested information
|
||||
return static_cast< bool >(Core::Get().GetVehicle(m_ID).mFlags & ENF_DIST_TRACK);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CVehicle::SetTrackDistance(bool toggle) const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Assign the requested information
|
||||
if (toggle)
|
||||
{
|
||||
Core::Get().GetVehicle(m_ID).mFlags |= ENF_DIST_TRACK;
|
||||
}
|
||||
else
|
||||
{
|
||||
Core::Get().GetVehicle(m_ID).mFlags ^= ENF_DIST_TRACK;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Float32 CVehicle::GetPositionX() const
|
||||
{
|
||||
@ -2027,6 +2070,8 @@ void Register_CVehicle(HSQUIRRELVM vm)
|
||||
.Prop(_SC("LastHealth"), &CVehicle::GetLastHealth)
|
||||
.Prop(_SC("LastPosition"), &CVehicle::GetLastPosition)
|
||||
.Prop(_SC("LastRotation"), &CVehicle::GetLastRotation)
|
||||
.Prop(_SC("Distance"), &CVehicle::GetDistance, &CVehicle::SetDistance)
|
||||
.Prop(_SC("TrackDistance"), &CVehicle::GetTrackDistance, &CVehicle::SetTrackDistance)
|
||||
.Prop(_SC("PosX"), &CVehicle::GetPositionX, &CVehicle::SetPositionX)
|
||||
.Prop(_SC("PosY"), &CVehicle::GetPositionY, &CVehicle::SetPositionY)
|
||||
.Prop(_SC("PosZ"), &CVehicle::GetPositionZ, &CVehicle::SetPositionZ)
|
||||
|
@ -687,15 +687,35 @@ public:
|
||||
Float32 GetLastHealth() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the last known position for the managed player entity.
|
||||
* Retrieve the last known position for the managed vehicle entity.
|
||||
*/
|
||||
const Vector3 & GetLastPosition() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the last known rotation for the managed player entity.
|
||||
* Retrieve the last known rotation for the managed vehicle entity.
|
||||
*/
|
||||
const Quaternion & GetLastRotation() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the distance traveled by the managed vehicle entity while tracking was enabled.
|
||||
*/
|
||||
SQFloat GetDistance() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the distance traveled by the managed vehicle entity.
|
||||
*/
|
||||
void SetDistance(SQFloat distance) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether distance tracking is enabled for the managed vehicle entity.
|
||||
*/
|
||||
bool GetTrackDistance() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set whether distance tracking is enabled for the managed vehicle entity.
|
||||
*/
|
||||
void SetTrackDistance(bool toggle) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the position on the x axis of the managed vehicle entity.
|
||||
*/
|
||||
|
@ -438,7 +438,8 @@ enum EntityFlags
|
||||
ENF_DEFAULT = (0),
|
||||
ENF_OWNED = (1u << 1u),
|
||||
ENF_LOCKED = (1u << 2u),
|
||||
ENF_AREA_TRACK = (1u << 3u)
|
||||
ENF_AREA_TRACK = (1u << 3u),
|
||||
ENF_DIST_TRACK = (1u << 4u)
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user