Skip to content

Commit 19eb2e6

Browse files
authored
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
1 parent 9743f81 commit 19eb2e6

17 files changed

+1205
-28
lines changed

Client/mods/deathmatch/logic/CClientColPolygon.cpp

Lines changed: 64 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,77 @@ void CClientColPolygon::SetPosition(const CVector& vecPosition)
6969
// Add queued collider refresh for v1.1
7070
}
7171

72-
void CClientColPolygon::AddPoint(CVector2D vecPoint)
72+
bool CClientColPolygon::AddPoint(CVector2D vecPoint, int iPointIndex)
7373
{
74-
float fDistanceX = vecPoint.fX - m_vecPosition.fX;
75-
float fDistanceY = vecPoint.fY - m_vecPosition.fY;
74+
if (iPointIndex < 0)
75+
{
76+
m_Points.push_back(vecPoint);
77+
}
78+
else
79+
{
80+
if (iPointIndex >= m_Points.size())
81+
return false;
7682

77-
float fDist = sqrt(fDistanceX * fDistanceX + fDistanceY * fDistanceY);
83+
m_Points.insert(m_Points.begin() + iPointIndex, vecPoint);
84+
}
7885

79-
if (fDist > m_fRadius)
86+
CVector2D vecDistance = vecPoint - m_vecPosition;
87+
float fDistance = vecDistance.Length();
88+
89+
if (fDistance > m_fRadius)
8090
{
81-
m_fRadius = fDist;
91+
m_fRadius = fDistance;
8292
SizeChanged();
8393
}
8494

85-
m_Points.push_back(vecPoint);
95+
return true;
96+
}
97+
98+
bool CClientColPolygon::RemovePoint(unsigned int uiPointIndex)
99+
{
100+
if (m_Points.size() <= 3)
101+
return false;
102+
103+
if (uiPointIndex >= m_Points.size())
104+
return false;
105+
106+
m_Points.erase(m_Points.begin() + uiPointIndex);
107+
108+
m_fRadius = 0.0f;
109+
for (auto vecPoint : m_Points)
110+
{
111+
CVector2D vecDistance = vecPoint - m_vecPosition;
112+
float fDistance = vecDistance.Length();
113+
114+
if (fDistance > m_fRadius)
115+
m_fRadius = fDistance;
116+
}
117+
118+
SizeChanged();
119+
120+
return true;
121+
}
122+
123+
bool CClientColPolygon::SetPointPosition(unsigned int uiPointIndex, const CVector2D& vecPoint)
124+
{
125+
if (uiPointIndex >= m_Points.size())
126+
return false;
127+
128+
m_Points[uiPointIndex] = vecPoint;
129+
130+
m_fRadius = 0.0f;
131+
for (auto vecPoint : m_Points)
132+
{
133+
CVector2D vecDistance = vecPoint - m_vecPosition;
134+
float fDistance = vecDistance.Length();
135+
136+
if (fDistance > m_fRadius)
137+
m_fRadius = fDistance;
138+
}
139+
140+
SizeChanged();
141+
142+
return true;
86143
}
87144

88145
bool CClientColPolygon::IsInBounds(CVector vecPoint)

Client/mods/deathmatch/logic/CClientColPolygon.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ class CClientColPolygon : public CClientColShape
2626

2727
void SetPosition(const CVector& vecPosition);
2828

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

3133
unsigned int CountPoints() const { return static_cast<unsigned int>(m_Points.size()); };
3234
std::vector<CVector2D>::const_iterator IterBegin() { return m_Points.begin(); };

Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp

Lines changed: 134 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,7 +1441,7 @@ bool CStaticFunctionDefinitions::SetElementModel(CClientEntity& Entity, unsigned
14411441
case CCLIENTPLAYER:
14421442
{
14431443
// Grab the model
1444-
CClientPed& Ped = static_cast<CClientPed&>(Entity);
1444+
CClientPed& Ped = static_cast<CClientPed&>(Entity);
14451445
const unsigned short usCurrentModel = static_cast<ushort>(Ped.GetModel());
14461446

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

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

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

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

16711671
if (bRawInput)
1672-
cs = Ped.m_rawControllerState; // use the raw controller values without MTA glitch fixes modifying our raw inputs
1672+
cs = Ped.m_rawControllerState; // use the raw controller values without MTA glitch fixes modifying our raw inputs
16731673
else
16741674
Ped.GetControllerState(cs);
16751675

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

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

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

7214+
bool CStaticFunctionDefinitions::GetColShapeRadius(CClientColShape* pColShape, float& fRadius)
7215+
{
7216+
switch (pColShape->GetShapeType())
7217+
{
7218+
case COLSHAPE_CIRCLE:
7219+
fRadius = static_cast<CClientColCircle*>(pColShape)->GetRadius();
7220+
break;
7221+
case COLSHAPE_SPHERE:
7222+
fRadius = static_cast<CClientColSphere*>(pColShape)->GetRadius();
7223+
break;
7224+
case COLSHAPE_TUBE:
7225+
fRadius = static_cast<CClientColTube*>(pColShape)->GetRadius();
7226+
break;
7227+
default:
7228+
return false;
7229+
}
7230+
7231+
return true;
7232+
}
7233+
7234+
bool CStaticFunctionDefinitions::SetColShapeRadius(CClientColShape* pColShape, float fRadius)
7235+
{
7236+
if (fRadius < 0.0f)
7237+
fRadius = 0.0f;
7238+
7239+
switch (pColShape->GetShapeType())
7240+
{
7241+
case COLSHAPE_CIRCLE:
7242+
static_cast<CClientColCircle*>(pColShape)->SetRadius(fRadius);
7243+
break;
7244+
case COLSHAPE_SPHERE:
7245+
static_cast<CClientColSphere*>(pColShape)->SetRadius(fRadius);
7246+
break;
7247+
case COLSHAPE_TUBE:
7248+
static_cast<CClientColTube*>(pColShape)->SetRadius(fRadius);
7249+
break;
7250+
default:
7251+
return false;
7252+
}
7253+
7254+
RefreshColShapeColliders(pColShape);
7255+
7256+
return true;
7257+
}
7258+
7259+
bool CStaticFunctionDefinitions::SetColShapeSize(CClientColShape* pColShape, CVector& vecSize)
7260+
{
7261+
if (vecSize.fX < 0.0f)
7262+
vecSize.fX = 0.0f;
7263+
if (vecSize.fY < 0.0f)
7264+
vecSize.fY = 0.0f;
7265+
if (vecSize.fZ < 0.0f)
7266+
vecSize.fZ = 0.0f;
7267+
7268+
switch (pColShape->GetShapeType())
7269+
{
7270+
case COLSHAPE_RECTANGLE:
7271+
{
7272+
static_cast<CClientColRectangle*>(pColShape)->SetSize(vecSize);
7273+
break;
7274+
}
7275+
case COLSHAPE_CUBOID:
7276+
{
7277+
static_cast<CClientColCuboid*>(pColShape)->SetSize(vecSize);
7278+
break;
7279+
}
7280+
case COLSHAPE_TUBE:
7281+
{
7282+
static_cast<CClientColTube*>(pColShape)->SetHeight(vecSize.fX);
7283+
break;
7284+
}
7285+
default:
7286+
return false;
7287+
}
7288+
7289+
RefreshColShapeColliders(pColShape);
7290+
7291+
return true;
7292+
}
7293+
7294+
bool CStaticFunctionDefinitions::GetColPolygonPointPosition(CClientColPolygon* pColPolygon, uint uiPointIndex, CVector2D& vecPoint)
7295+
{
7296+
if (uiPointIndex < pColPolygon->CountPoints())
7297+
{
7298+
vecPoint = *(pColPolygon->IterBegin() + uiPointIndex);
7299+
return true;
7300+
}
7301+
7302+
return false;
7303+
}
7304+
7305+
bool CStaticFunctionDefinitions::SetColPolygonPointPosition(CClientColPolygon* pColPolygon, uint uiPointIndex, const CVector2D& vecPoint)
7306+
{
7307+
if (pColPolygon->SetPointPosition(uiPointIndex, vecPoint))
7308+
{
7309+
RefreshColShapeColliders(pColPolygon);
7310+
return true;
7311+
}
7312+
7313+
return false;
7314+
}
7315+
7316+
bool CStaticFunctionDefinitions::AddColPolygonPoint(CClientColPolygon* pColPolygon, int iPointIndex, const CVector2D& vecPoint)
7317+
{
7318+
if (pColPolygon->AddPoint(vecPoint, iPointIndex))
7319+
{
7320+
RefreshColShapeColliders(pColPolygon);
7321+
return true;
7322+
}
7323+
7324+
return false;
7325+
}
7326+
7327+
bool CStaticFunctionDefinitions::RemoveColPolygonPoint(CClientColPolygon* pColPolygon, uint uiPointIndex)
7328+
{
7329+
if (pColPolygon->RemovePoint(uiPointIndex))
7330+
{
7331+
RefreshColShapeColliders(pColPolygon);
7332+
return true;
7333+
}
7334+
7335+
return false;
7336+
}
7337+
72147338
// Make sure all colliders for a colshape are up to date
72157339
void CStaticFunctionDefinitions::RefreshColShapeColliders(CClientColShape* pColShape)
72167340
{

Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,18 @@ class CStaticFunctionDefinitions
665665
static bool IsInsideColShape(CClientColShape* pColShape, const CVector& vecPosition, bool& inside);
666666
static void RefreshColShapeColliders(CClientColShape* pColShape);
667667

668+
// Shape get functions
669+
static bool GetColShapeRadius(CClientColShape* pColShape, float& fRadius);
670+
static bool GetColPolygonPointPosition(CClientColPolygon* pColPolygon, uint uiPointIndex, CVector2D& vecPoint);
671+
672+
// Shape set functions
673+
static bool SetColShapeRadius(CClientColShape* pColShape, float fRadius);
674+
static bool SetColShapeSize(CClientColShape* pColShape, CVector& vecSize);
675+
static bool SetColPolygonPointPosition(CClientColPolygon* pColPolygon, uint uiPointIndex, const CVector2D& vecPoint);
676+
677+
static bool AddColPolygonPoint(CClientColPolygon* pColPolygon, int iPointIndex, const CVector2D& vecPoint);
678+
static bool RemoveColPolygonPoint(CClientColPolygon* pColPolygon, uint iPointIndex);
679+
668680
// Weapon funcs
669681
static bool GetWeaponNameFromID(unsigned char ucID, SString& strOutName);
670682
static bool GetWeaponIDFromName(const char* szName, unsigned char& ucID);

0 commit comments

Comments
 (0)