Skip to content
Permalink
Browse files

Add functions to manipulate colshapes parameters (#1215)

* Add get/setColShapeRadius and get/setColShapeHeight

* Add get/setColShapeSize

* Return error when using wrong col shape

* Remove get/setColShapeHeight

* Add colpolygon functions

* Remove redundant source checks in CColShapeRPCs

* Remove sync time context

* Return false and print warning instead of error
  • Loading branch information
StrixG committed Jan 30, 2020
1 parent 9743f81 commit 19eb2e670f823831ceb52c557a0f35127148aa57
@@ -69,20 +69,77 @@ void CClientColPolygon::SetPosition(const CVector& vecPosition)
// Add queued collider refresh for v1.1
}

void CClientColPolygon::AddPoint(CVector2D vecPoint)
bool CClientColPolygon::AddPoint(CVector2D vecPoint, int iPointIndex)
{
float fDistanceX = vecPoint.fX - m_vecPosition.fX;
float fDistanceY = vecPoint.fY - m_vecPosition.fY;
if (iPointIndex < 0)
{
m_Points.push_back(vecPoint);
}
else
{
if (iPointIndex >= m_Points.size())
return false;

float fDist = sqrt(fDistanceX * fDistanceX + fDistanceY * fDistanceY);
m_Points.insert(m_Points.begin() + iPointIndex, vecPoint);
}

if (fDist > m_fRadius)
CVector2D vecDistance = vecPoint - m_vecPosition;
float fDistance = vecDistance.Length();

if (fDistance > m_fRadius)
{
m_fRadius = fDist;
m_fRadius = fDistance;
SizeChanged();
}

m_Points.push_back(vecPoint);
return true;
}

bool CClientColPolygon::RemovePoint(unsigned int uiPointIndex)
{
if (m_Points.size() <= 3)
return false;

if (uiPointIndex >= m_Points.size())
return false;

m_Points.erase(m_Points.begin() + uiPointIndex);

m_fRadius = 0.0f;
for (auto vecPoint : m_Points)
{
CVector2D vecDistance = vecPoint - m_vecPosition;
float fDistance = vecDistance.Length();

if (fDistance > m_fRadius)
m_fRadius = fDistance;
}

SizeChanged();

return true;
}

bool CClientColPolygon::SetPointPosition(unsigned int uiPointIndex, const CVector2D& vecPoint)
{
if (uiPointIndex >= m_Points.size())
return false;

m_Points[uiPointIndex] = vecPoint;

m_fRadius = 0.0f;
for (auto vecPoint : m_Points)
{
CVector2D vecDistance = vecPoint - m_vecPosition;
float fDistance = vecDistance.Length();

if (fDistance > m_fRadius)
m_fRadius = fDistance;
}

SizeChanged();

return true;
}

bool CClientColPolygon::IsInBounds(CVector vecPoint)
@@ -26,7 +26,9 @@ class CClientColPolygon : public CClientColShape

void SetPosition(const CVector& vecPosition);

void AddPoint(CVector2D vecPoint);
bool AddPoint(CVector2D vecPoint, int iPointIndex = -1);
bool SetPointPosition(unsigned int uiPointIndex, const CVector2D& vecPoint);
bool RemovePoint(unsigned int uiPointIndex);

unsigned int CountPoints() const { return static_cast<unsigned int>(m_Points.size()); };
std::vector<CVector2D>::const_iterator IterBegin() { return m_Points.begin(); };
@@ -1441,7 +1441,7 @@ bool CStaticFunctionDefinitions::SetElementModel(CClientEntity& Entity, unsigned
case CCLIENTPLAYER:
{
// Grab the model
CClientPed& Ped = static_cast<CClientPed&>(Entity);
CClientPed& Ped = static_cast<CClientPed&>(Entity);
const unsigned short usCurrentModel = static_cast<ushort>(Ped.GetModel());

if (usCurrentModel == usModel)
@@ -1458,7 +1458,7 @@ bool CStaticFunctionDefinitions::SetElementModel(CClientEntity& Entity, unsigned
}
case CCLIENTVEHICLE:
{
CClientVehicle& Vehicle = static_cast<CClientVehicle&>(Entity);
CClientVehicle& Vehicle = static_cast<CClientVehicle&>(Entity);
const unsigned short usCurrentModel = Vehicle.GetModel();

if (usCurrentModel == usModel)
@@ -1478,7 +1478,7 @@ bool CStaticFunctionDefinitions::SetElementModel(CClientEntity& Entity, unsigned
case CCLIENTOBJECT:
case CCLIENTWEAPON:
{
CClientObject& Object = static_cast<CClientObject&>(Entity);
CClientObject& Object = static_cast<CClientObject&>(Entity);
const unsigned short usCurrentModel = Object.GetModel();

if (usCurrentModel == usModel)
@@ -1497,7 +1497,7 @@ bool CStaticFunctionDefinitions::SetElementModel(CClientEntity& Entity, unsigned
}
case CCLIENTPROJECTILE:
{
CClientProjectile& Projectile = static_cast<CClientProjectile&>(Entity);
CClientProjectile& Projectile = static_cast<CClientProjectile&>(Entity);
const unsigned short usCurrentModel = Projectile.GetModel();

if (usCurrentModel == usModel)
@@ -1665,11 +1665,11 @@ bool CStaticFunctionDefinitions::GetPedAnalogControlState(CClientPed& Ped, const
if (Ped.GetType() == CCLIENTPLAYER)
{
CControllerState cs;
bool bOnFoot = (!Ped.GetRealOccupiedVehicle());
unsigned int uiIndex;
bool bOnFoot = (!Ped.GetRealOccupiedVehicle());
unsigned int uiIndex;

if (bRawInput)
cs = Ped.m_rawControllerState; // use the raw controller values without MTA glitch fixes modifying our raw inputs
cs = Ped.m_rawControllerState; // use the raw controller values without MTA glitch fixes modifying our raw inputs
else
Ped.GetControllerState(cs);

@@ -2165,7 +2165,7 @@ bool CStaticFunctionDefinitions::SetPedAnimation(CClientEntity& Entity, const SS
// Play the gateway animation
const SString& strGateWayBlockName = g_pGame->GetAnimManager()->GetGateWayBlockName();
std::unique_ptr<CAnimBlock> pBlock = g_pGame->GetAnimManager()->GetAnimationBlock(strGateWayBlockName);
auto pCustomAnimBlendHierarchy = pIFP->GetAnimationHierarchy(szAnimName);
auto pCustomAnimBlendHierarchy = pIFP->GetAnimationHierarchy(szAnimName);
if ((pBlock) && (pCustomAnimBlendHierarchy != nullptr))
{
Ped.SetNextAnimationCustom(pIFP, szAnimName);
@@ -7014,10 +7014,10 @@ bool CStaticFunctionDefinitions::GetAnalogControlState(const char* szControl, fl
{
CControllerState cs;
CClientPlayer* pLocalPlayer = m_pPlayerManager->GetLocalPlayer();
bool bOnFoot = (!pLocalPlayer->GetRealOccupiedVehicle());
bool bOnFoot = (!pLocalPlayer->GetRealOccupiedVehicle());

if (bRawInput)
cs = pLocalPlayer->m_rawControllerState; // use the raw controller values without MTA glitch fixes modifying our raw inputs
cs = pLocalPlayer->m_rawControllerState; // use the raw controller values without MTA glitch fixes modifying our raw inputs
else
pLocalPlayer->GetControllerState(cs);

@@ -7211,6 +7211,130 @@ CClientColTube* CStaticFunctionDefinitions::CreateColTube(CResource& Resource, c
return pShape;
}

bool CStaticFunctionDefinitions::GetColShapeRadius(CClientColShape* pColShape, float& fRadius)
{
switch (pColShape->GetShapeType())
{
case COLSHAPE_CIRCLE:
fRadius = static_cast<CClientColCircle*>(pColShape)->GetRadius();
break;
case COLSHAPE_SPHERE:
fRadius = static_cast<CClientColSphere*>(pColShape)->GetRadius();
break;
case COLSHAPE_TUBE:
fRadius = static_cast<CClientColTube*>(pColShape)->GetRadius();
break;
default:
return false;
}

return true;
}

bool CStaticFunctionDefinitions::SetColShapeRadius(CClientColShape* pColShape, float fRadius)
{
if (fRadius < 0.0f)
fRadius = 0.0f;

switch (pColShape->GetShapeType())
{
case COLSHAPE_CIRCLE:
static_cast<CClientColCircle*>(pColShape)->SetRadius(fRadius);
break;
case COLSHAPE_SPHERE:
static_cast<CClientColSphere*>(pColShape)->SetRadius(fRadius);
break;
case COLSHAPE_TUBE:
static_cast<CClientColTube*>(pColShape)->SetRadius(fRadius);
break;
default:
return false;
}

RefreshColShapeColliders(pColShape);

return true;
}

bool CStaticFunctionDefinitions::SetColShapeSize(CClientColShape* pColShape, CVector& vecSize)
{
if (vecSize.fX < 0.0f)
vecSize.fX = 0.0f;
if (vecSize.fY < 0.0f)
vecSize.fY = 0.0f;
if (vecSize.fZ < 0.0f)
vecSize.fZ = 0.0f;

switch (pColShape->GetShapeType())
{
case COLSHAPE_RECTANGLE:
{
static_cast<CClientColRectangle*>(pColShape)->SetSize(vecSize);
break;
}
case COLSHAPE_CUBOID:
{
static_cast<CClientColCuboid*>(pColShape)->SetSize(vecSize);
break;
}
case COLSHAPE_TUBE:
{
static_cast<CClientColTube*>(pColShape)->SetHeight(vecSize.fX);
break;
}
default:
return false;
}

RefreshColShapeColliders(pColShape);

return true;
}

bool CStaticFunctionDefinitions::GetColPolygonPointPosition(CClientColPolygon* pColPolygon, uint uiPointIndex, CVector2D& vecPoint)
{
if (uiPointIndex < pColPolygon->CountPoints())
{
vecPoint = *(pColPolygon->IterBegin() + uiPointIndex);
return true;
}

return false;
}

bool CStaticFunctionDefinitions::SetColPolygonPointPosition(CClientColPolygon* pColPolygon, uint uiPointIndex, const CVector2D& vecPoint)
{
if (pColPolygon->SetPointPosition(uiPointIndex, vecPoint))
{
RefreshColShapeColliders(pColPolygon);
return true;
}

return false;
}

bool CStaticFunctionDefinitions::AddColPolygonPoint(CClientColPolygon* pColPolygon, int iPointIndex, const CVector2D& vecPoint)
{
if (pColPolygon->AddPoint(vecPoint, iPointIndex))
{
RefreshColShapeColliders(pColPolygon);
return true;
}

return false;
}

bool CStaticFunctionDefinitions::RemoveColPolygonPoint(CClientColPolygon* pColPolygon, uint uiPointIndex)
{
if (pColPolygon->RemovePoint(uiPointIndex))
{
RefreshColShapeColliders(pColPolygon);
return true;
}

return false;
}

// Make sure all colliders for a colshape are up to date
void CStaticFunctionDefinitions::RefreshColShapeColliders(CClientColShape* pColShape)
{
@@ -665,6 +665,18 @@ class CStaticFunctionDefinitions
static bool IsInsideColShape(CClientColShape* pColShape, const CVector& vecPosition, bool& inside);
static void RefreshColShapeColliders(CClientColShape* pColShape);

// Shape get functions
static bool GetColShapeRadius(CClientColShape* pColShape, float& fRadius);
static bool GetColPolygonPointPosition(CClientColPolygon* pColPolygon, uint uiPointIndex, CVector2D& vecPoint);

// Shape set functions
static bool SetColShapeRadius(CClientColShape* pColShape, float fRadius);
static bool SetColShapeSize(CClientColShape* pColShape, CVector& vecSize);
static bool SetColPolygonPointPosition(CClientColPolygon* pColPolygon, uint uiPointIndex, const CVector2D& vecPoint);

static bool AddColPolygonPoint(CClientColPolygon* pColPolygon, int iPointIndex, const CVector2D& vecPoint);
static bool RemoveColPolygonPoint(CClientColPolygon* pColPolygon, uint iPointIndex);

// Weapon funcs
static bool GetWeaponNameFromID(unsigned char ucID, SString& strOutName);
static bool GetWeaponIDFromName(const char* szName, unsigned char& ucID);

0 comments on commit 19eb2e6

Please sign in to comment.
You can’t perform that action at this time.