Skip to content

Commit 3ed17df

Browse files
committed
Extending the ColShape class with point checking functionality
1 parent bad2a48 commit 3ed17df

File tree

8 files changed

+75
-1
lines changed

8 files changed

+75
-1
lines changed

Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6761,6 +6761,13 @@ CClientColShape* CStaticFunctionDefinitions::GetElementColShape(CClientEntity* p
67616761
return pColShape;
67626762
}
67636763

6764+
bool CStaticFunctionDefinitions::IsInsideColShape(CClientColShape* pColShape, const CVector& vecPosition, bool& inside)
6765+
{
6766+
inside = pColShape->DoHitDetection(vecPosition, 0);
6767+
6768+
return true;
6769+
}
6770+
67646771
bool CStaticFunctionDefinitions::GetWeaponNameFromID(unsigned char ucID, SString& strOutName)
67656772
{
67666773
if (ucID <= 59)

Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,7 @@ class CStaticFunctionDefinitions
631631
static CClientColPolygon* CreateColPolygon(CResource& Resource, const CVector2D& vecPosition);
632632
static CClientColTube* CreateColTube(CResource& Resource, const CVector& vecPosition, float fRadius, float fHeight);
633633
static CClientColShape* GetElementColShape(CClientEntity* pEntity);
634+
static bool IsInsideColShape(CClientColShape* pColShape, const CVector& vecPosition, bool& inside);
634635
static void RefreshColShapeColliders(CClientColShape* pColShape);
635636

636637
// Weapon funcs

Client/mods/deathmatch/logic/luadefs/CLuaColShapeDefs.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ void CLuaColShapeDefs::LoadFunctions(void)
1919
CLuaCFunctions::AddFunction("createColRectangle", CreateColRectangle);
2020
CLuaCFunctions::AddFunction("createColPolygon", CreateColPolygon);
2121
CLuaCFunctions::AddFunction("createColTube", CreateColTube);
22+
CLuaCFunctions::AddFunction("isInsideColShape", IsInsideColShape);
2223
}
2324

2425
void CLuaColShapeDefs::AddClass(lua_State* luaVM)
@@ -33,6 +34,7 @@ void CLuaColShapeDefs::AddClass(lua_State* luaVM)
3334
lua_classfunction(luaVM, "Polygon", "createColPolygon");
3435

3536
lua_classfunction(luaVM, "getElementsWithin", "getElementsWithinColShape");
37+
lua_classfunction(luaVM, "isInside", "isInsideColShape");
3638
lua_classvariable(luaVM, "elementsWithin", NULL, "getElementsWithinColShape");
3739

3840
lua_registerclass(luaVM, "ColShape", "Element");
@@ -308,3 +310,29 @@ int CLuaColShapeDefs::CreateColTube(lua_State* luaVM)
308310
lua_pushboolean(luaVM, false);
309311
return 1;
310312
}
313+
314+
int CLuaColShapeDefs::IsInsideColShape(lua_State* luaVM)
315+
{
316+
// bool isInsideColShape ( colshape theColShape, float posX, float posY, float posZ )
317+
CClientColShape* pColShape;
318+
CVector vecPosition;
319+
320+
CScriptArgReader argStream(luaVM);
321+
argStream.ReadUserData(pColShape);
322+
argStream.ReadVector3D(vecPosition);
323+
324+
if (!argStream.HasErrors())
325+
{
326+
bool bInside = false;
327+
if (CStaticFunctionDefinitions::IsInsideColShape(pColShape, vecPosition, bInside))
328+
{
329+
lua_pushboolean(luaVM, bInside);
330+
return 1;
331+
}
332+
}
333+
else
334+
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());
335+
336+
lua_pushboolean(luaVM, false);
337+
return 1;
338+
}

Client/mods/deathmatch/logic/luadefs/CLuaColShapeDefs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ class CLuaColShapeDefs : public CLuaDefs
2424
LUA_DECLARE(CreateColRectangle);
2525
LUA_DECLARE(CreateColPolygon);
2626
LUA_DECLARE(CreateColTube);
27+
LUA_DECLARE(IsInsideColShape);
2728
};

Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9323,6 +9323,13 @@ CColTube* CStaticFunctionDefinitions::CreateColTube(CResource* pResource, const
93239323
return pColShape;
93249324
}
93259325

9326+
bool CStaticFunctionDefinitions::IsInsideColShape(CColShape* pColShape, const CVector& vecPosition, bool& inside)
9327+
{
9328+
inside = pColShape->DoHitDetection(vecPosition);
9329+
9330+
return true;
9331+
}
9332+
93269333
// Make sure all colliders for a colshape are up to date
93279334
void CStaticFunctionDefinitions::RefreshColShapeColliders(CColShape* pColShape)
93289335
{

Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ class CStaticFunctionDefinitions
442442
static CColRectangle* CreateColRectangle(CResource* pResource, const CVector2D& vecPosition, const CVector2D& vecSize);
443443
static CColPolygon* CreateColPolygon(CResource* pResource, const std::vector<CVector2D>& vecPointList);
444444
static CColTube* CreateColTube(CResource* pResource, const CVector& vecPosition, float fRadius, float fHeight);
445+
static bool IsInsideColShape(CColShape* pColShape, const CVector& vecPosition, bool& inside);
445446
static void RefreshColShapeColliders(CColShape* pColShape);
446447

447448
// Weapon funcs

Server/mods/deathmatch/logic/luadefs/CLuaColShapeDefs.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ void CLuaColShapeDefs::LoadFunctions()
2020
CLuaCFunctions::AddFunction("createColRectangle", CreateColRectangle);
2121
CLuaCFunctions::AddFunction("createColPolygon", CreateColPolygon);
2222
CLuaCFunctions::AddFunction("createColTube", CreateColTube);
23+
CLuaCFunctions::AddFunction("isInsideColShape", IsInsideColShape);
2324
}
2425

2526
void CLuaColShapeDefs::AddClass(lua_State* luaVM)
@@ -34,6 +35,7 @@ void CLuaColShapeDefs::AddClass(lua_State* luaVM)
3435
lua_classfunction(luaVM, "Polygon", "createColPolygon");
3536

3637
lua_classfunction(luaVM, "getElementsWithin", "getElementsWithinColShape");
38+
lua_classfunction(luaVM, "isInside", "isInsideColShape");
3739
lua_registerclass(luaVM, "ColShape", "Element");
3840
}
3941

@@ -297,3 +299,29 @@ int CLuaColShapeDefs::CreateColTube(lua_State* luaVM)
297299
lua_pushboolean(luaVM, false);
298300
return 1;
299301
}
302+
303+
int CLuaColShapeDefs::IsInsideColShape(lua_State* luaVM)
304+
{
305+
// bool isInsideColShape ( colshape theColShape, float posX, float posY, float posZ )
306+
CColShape* pColShape;
307+
CVector vecPosition;
308+
309+
CScriptArgReader argStream(luaVM);
310+
argStream.ReadUserData(pColShape);
311+
argStream.ReadVector3D(vecPosition);
312+
313+
if (!argStream.HasErrors())
314+
{
315+
bool bInside = false;
316+
if (CStaticFunctionDefinitions::IsInsideColShape(pColShape, vecPosition, bInside))
317+
{
318+
lua_pushboolean(luaVM, bInside);
319+
return 1;
320+
}
321+
}
322+
else
323+
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());
324+
325+
lua_pushboolean(luaVM, false);
326+
return 1;
327+
}

Server/mods/deathmatch/logic/luadefs/CLuaColShapeDefs.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ class CLuaColShapeDefs : public CLuaDefs
2525
LUA_DECLARE(CreateColRectangle);
2626
LUA_DECLARE(CreateColPolygon);
2727
LUA_DECLARE(CreateColTube);
28-
};
28+
LUA_DECLARE(IsInsideColShape);
29+
};

0 commit comments

Comments
 (0)