Skip to content

Commit 0a7a28a

Browse files
committed
Merge branch 'feature/queryColShapePosition'
2 parents d28eb11 + 2a5520f commit 0a7a28a

File tree

8 files changed

+78
-1
lines changed

8 files changed

+78
-1
lines changed

Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6804,6 +6804,13 @@ CClientColShape* CStaticFunctionDefinitions::GetElementColShape(CClientEntity* p
68046804
return pColShape;
68056805
}
68066806

6807+
bool CStaticFunctionDefinitions::IsInsideColShape(CClientColShape* pColShape, const CVector& vecPosition, bool& inside)
6808+
{
6809+
inside = pColShape->DoHitDetection(vecPosition, 0);
6810+
6811+
return true;
6812+
}
6813+
68076814
bool CStaticFunctionDefinitions::GetWeaponNameFromID(unsigned char ucID, SString& strOutName)
68086815
{
68096816
if (ucID <= 59)

Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h

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

638639
// Weapon funcs

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ void CLuaColShapeDefs::LoadFunctions(void)
1919
CLuaCFunctions::AddFunction("createColRectangle", CreateColRectangle);
2020
CLuaCFunctions::AddFunction("createColPolygon", CreateColPolygon);
2121
CLuaCFunctions::AddFunction("createColTube", CreateColTube);
22+
23+
CLuaCFunctions::AddFunction("isInsideColShape", IsInsideColShape);
2224
CLuaCFunctions::AddFunction("getColShapeType", GetColShapeType);
2325
}
2426

@@ -34,8 +36,10 @@ void CLuaColShapeDefs::AddClass(lua_State* luaVM)
3436
lua_classfunction(luaVM, "Polygon", "createColPolygon");
3537

3638
lua_classfunction(luaVM, "getElementsWithin", "getElementsWithinColShape");
39+
lua_classfunction(luaVM, "isInside", "isInsideColShape");
3740
lua_classfunction(luaVM, "getShapeType", "getColShapeType");
3841

42+
lua_classvariable(luaVM, "elementsWithin", nullptr, "getElementsWithinColShape");
3943
lua_classvariable(luaVM, "shapeType", nullptr, "getColShapeType");
4044

4145
lua_registerclass(luaVM, "ColShape", "Element");
@@ -336,3 +340,29 @@ int CLuaColShapeDefs::CreateColTube(lua_State* luaVM)
336340
lua_pushboolean(luaVM, false);
337341
return 1;
338342
}
343+
344+
int CLuaColShapeDefs::IsInsideColShape(lua_State* luaVM)
345+
{
346+
// bool isInsideColShape ( colshape theColShape, float posX, float posY, float posZ )
347+
CClientColShape* pColShape;
348+
CVector vecPosition;
349+
350+
CScriptArgReader argStream(luaVM);
351+
argStream.ReadUserData(pColShape);
352+
argStream.ReadVector3D(vecPosition);
353+
354+
if (!argStream.HasErrors())
355+
{
356+
bool bInside = false;
357+
if (CStaticFunctionDefinitions::IsInsideColShape(pColShape, vecPosition, bInside))
358+
{
359+
lua_pushboolean(luaVM, bInside);
360+
return 1;
361+
}
362+
}
363+
else
364+
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());
365+
366+
lua_pushboolean(luaVM, false);
367+
return 1;
368+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ class CLuaColShapeDefs : public CLuaDefs
2525
LUA_DECLARE(CreateColPolygon);
2626
LUA_DECLARE(CreateColTube);
2727

28+
LUA_DECLARE(IsInsideColShape);
2829
LUA_DECLARE(GetColShapeType);
2930
};

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: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ void CLuaColShapeDefs::LoadFunctions()
1919
CLuaCFunctions::AddFunction("createColRectangle", CreateColRectangle);
2020
CLuaCFunctions::AddFunction("createColPolygon", CreateColPolygon);
2121
CLuaCFunctions::AddFunction("createColTube", CreateColTube);
22+
23+
CLuaCFunctions::AddFunction("isInsideColShape", IsInsideColShape);
2224
CLuaCFunctions::AddFunction("getColShapeType", GetColShapeType);
2325
}
2426

@@ -34,8 +36,9 @@ void CLuaColShapeDefs::AddClass(lua_State* luaVM)
3436
lua_classfunction(luaVM, "Polygon", "createColPolygon");
3537

3638
lua_classfunction(luaVM, "getElementsWithin", "getElementsWithinColShape");
37-
lua_classfunction(luaVM, "getShapeType", "getColShapeType");
39+
lua_classfunction(luaVM, "isInside", "isInsideColShape");
3840

41+
lua_classfunction(luaVM, "getShapeType", "getColShapeType");
3942
lua_classvariable(luaVM, "shapeType", nullptr, "getColShapeType");
4043

4144
lua_registerclass(luaVM, "ColShape", "Element");
@@ -326,3 +329,29 @@ int CLuaColShapeDefs::CreateColTube(lua_State* luaVM)
326329
lua_pushboolean(luaVM, false);
327330
return 1;
328331
}
332+
333+
int CLuaColShapeDefs::IsInsideColShape(lua_State* luaVM)
334+
{
335+
// bool isInsideColShape ( colshape theColShape, float posX, float posY, float posZ )
336+
CColShape* pColShape;
337+
CVector vecPosition;
338+
339+
CScriptArgReader argStream(luaVM);
340+
argStream.ReadUserData(pColShape);
341+
argStream.ReadVector3D(vecPosition);
342+
343+
if (!argStream.HasErrors())
344+
{
345+
bool bInside = false;
346+
if (CStaticFunctionDefinitions::IsInsideColShape(pColShape, vecPosition, bInside))
347+
{
348+
lua_pushboolean(luaVM, bInside);
349+
return 1;
350+
}
351+
}
352+
else
353+
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());
354+
355+
lua_pushboolean(luaVM, false);
356+
return 1;
357+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@ class CLuaColShapeDefs : public CLuaDefs
2626
LUA_DECLARE(CreateColPolygon);
2727
LUA_DECLARE(CreateColTube);
2828

29+
LUA_DECLARE(IsInsideColShape);
2930
LUA_DECLARE(GetColShapeType);
3031
};

0 commit comments

Comments
 (0)