Skip to content

Commit 84c680d

Browse files
committed
Add getElementsWithinRange
1 parent d2c8306 commit 84c680d

File tree

4 files changed

+75
-1
lines changed

4 files changed

+75
-1
lines changed

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ void CLuaElementDefs::LoadFunctions(void)
3636
CLuaCFunctions::AddFunction("isElementWithinColShape", IsElementWithinColShape);
3737
CLuaCFunctions::AddFunction("isElementWithinMarker", IsElementWithinMarker);
3838
CLuaCFunctions::AddFunction("getElementsWithinColShape", GetElementsWithinColShape);
39+
CLuaCFunctions::AddFunction("getElementsWithinRange", GetElementsWithinRange);
3940
CLuaCFunctions::AddFunction("getElementDimension", GetElementDimension);
4041
CLuaCFunctions::AddFunction("getElementBoundingBox", GetElementBoundingBox);
4142
CLuaCFunctions::AddFunction("getElementRadius", GetElementRadius);
@@ -139,6 +140,7 @@ void CLuaElementDefs::AddClass(lua_State* luaVM)
139140
lua_classfunction(luaVM, "getType", "getElementType");
140141
lua_classfunction(luaVM, "getInterior", "getElementInterior");
141142
lua_classfunction(luaVM, "getWithinColShape", "getElementsWithinColShape");
143+
lua_classfunction(luaVM, "getWithinRange", "getElementsWithinRange");
142144
lua_classfunction(luaVM, "getDimension", "getElementDimension");
143145
lua_classfunction(luaVM, "getColShape", "getElementColShape");
144146
lua_classfunction(luaVM, "getAlpha", "getElementAlpha");
@@ -928,6 +930,40 @@ int CLuaElementDefs::GetElementsWithinColShape(lua_State* luaVM)
928930
return 1;
929931
}
930932

933+
int CLuaElementDefs::GetElementsWithinRange(lua_State* luaVM)
934+
{
935+
CVector position;
936+
float radius;
937+
938+
CScriptArgReader argStream(luaVM);
939+
argStream.ReadVector3D(position);
940+
argStream.ReadNumber(radius);
941+
942+
if (!argStream.HasErrors())
943+
{
944+
// Query the spatial database
945+
CClientEntityResult result;
946+
GetClientSpatialDatabase()->SphereQuery(result, CSphere{ position, radius });
947+
948+
lua_newtable(luaVM);
949+
unsigned int index = 0;
950+
951+
for (CClientEntity* entity : result)
952+
{
953+
lua_pushnumber(luaVM, ++index);
954+
lua_pushelement(luaVM, entity);
955+
lua_settable(luaVM, -3);
956+
}
957+
958+
return 1;
959+
}
960+
else
961+
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());
962+
963+
lua_pushboolean(luaVM, false);
964+
return 1;
965+
}
966+
931967
int CLuaElementDefs::GetElementDimension(lua_State* luaVM)
932968
{
933969
// Verify the argument

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class CLuaElementDefs : public CLuaDefs
3838
LUA_DECLARE(IsElementWithinColShape);
3939
LUA_DECLARE(IsElementWithinMarker);
4040
LUA_DECLARE(GetElementsWithinColShape);
41+
LUA_DECLARE(GetElementsWithinRange);
4142
LUA_DECLARE(GetElementDimension);
4243
LUA_DECLARE(GetElementZoneName);
4344
LUA_DECLARE(GetElementBoundingBox);

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ void CLuaElementDefs::LoadFunctions(void)
4444
CLuaCFunctions::AddFunction("getElementType", getElementType);
4545
CLuaCFunctions::AddFunction("getElementInterior", getElementInterior);
4646
CLuaCFunctions::AddFunction("getElementsWithinColShape", getElementsWithinColShape);
47+
CLuaCFunctions::AddFunction("getElementsWithinRange", getElementsWithinRange);
4748
CLuaCFunctions::AddFunction("getElementDimension", getElementDimension);
4849
CLuaCFunctions::AddFunction("getElementZoneName", getElementZoneName);
4950
CLuaCFunctions::AddFunction("getElementColShape", getElementColShape);
@@ -99,6 +100,7 @@ void CLuaElementDefs::AddClass(lua_State* luaVM)
99100
lua_classfunction(luaVM, "getByID", "getElementByID");
100101
lua_classfunction(luaVM, "getAllByType", "getElementsByType");
101102
lua_classfunction(luaVM, "getByIndex", "getElementByIndex");
103+
lua_classfunction(luaVM, "getWithinRange", "getElementsWithinRange");
102104

103105
lua_classfunction(luaVM, "create", "createElement");
104106
lua_classfunction(luaVM, "clone", "cloneElement");
@@ -986,6 +988,40 @@ int CLuaElementDefs::getElementsWithinColShape(lua_State* luaVM)
986988
return 1;
987989
}
988990

991+
int CLuaElementDefs::getElementsWithinRange(lua_State* luaVM)
992+
{
993+
CVector position;
994+
float radius;
995+
996+
CScriptArgReader argStream(luaVM);
997+
argStream.ReadVector3D(position);
998+
argStream.ReadNumber(radius);
999+
1000+
if (!argStream.HasErrors())
1001+
{
1002+
// Query the spatial database
1003+
CElementResult result;
1004+
GetSpatialDatabase()->SphereQuery(result, CSphere{ position, radius });
1005+
1006+
lua_newtable(luaVM);
1007+
unsigned int index = 0;
1008+
1009+
for (CElement* entity : result)
1010+
{
1011+
lua_pushnumber(luaVM, ++index);
1012+
lua_pushelement(luaVM, entity);
1013+
lua_settable(luaVM, -3);
1014+
}
1015+
1016+
return 1;
1017+
}
1018+
else
1019+
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());
1020+
1021+
lua_pushboolean(luaVM, false);
1022+
return 1;
1023+
}
1024+
9891025
int CLuaElementDefs::getElementDimension(lua_State* luaVM)
9901026
{
9911027
// int getElementDimension ( element theElement )

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class CLuaElementDefs : public CLuaDefs
4444
LUA_DECLARE(getElementsByType);
4545
LUA_DECLARE(getElementInterior);
4646
LUA_DECLARE(getElementsWithinColShape);
47+
LUA_DECLARE(getElementsWithinRange);
4748
LUA_DECLARE(getElementDimension);
4849
LUA_DECLARE(getElementZoneName);
4950
LUA_DECLARE(getElementColShape);
@@ -96,4 +97,4 @@ class CLuaElementDefs : public CLuaDefs
9697
LUA_DECLARE(setElementFrozen);
9798
LUA_DECLARE(setLowLODElement);
9899
LUA_DECLARE(setElementCallPropagationEnabled);
99-
};
100+
};

0 commit comments

Comments
 (0)