Skip to content

Commit de149ef

Browse files
committed
Add 'elementType' parameter to getElementsWithinRange
1 parent 922b85e commit de149ef

File tree

4 files changed

+22
-12
lines changed

4 files changed

+22
-12
lines changed

Client/mods/deathmatch/logic/CClientEntity.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,11 @@ CClientEntity::~CClientEntity(void)
171171
// return MapContains ( ms_ValidEntityMap, pEntity );
172172
//}
173173

174-
void CClientEntity::SetTypeName(const char* szName)
174+
void CClientEntity::SetTypeName(const SString& name)
175175
{
176176
CClientEntity::RemoveEntityFromRoot(m_uiTypeHash, this);
177-
m_strTypeName.AssignLeft(szName, MAX_TYPENAME_LENGTH);
178-
m_uiTypeHash = HashString(szName);
177+
m_strTypeName.AssignLeft(name, MAX_TYPENAME_LENGTH);
178+
m_uiTypeHash = HashString(name);
179179
if (IsFromRoot(m_pParent))
180180
CClientEntity::AddEntityFromRoot(m_uiTypeHash, this);
181181
}

Client/mods/deathmatch/logic/CClientEntity.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,9 @@ class CClientEntity : public CClientEntityBase
175175
const SString& GetName(void) const { return m_strName; }
176176
void SetName(const char* szName) { m_strName.AssignLeft(szName, MAX_ELEMENT_NAME_LENGTH); }
177177

178-
const char* GetTypeName(void) { return m_strTypeName; };
179-
unsigned int GetTypeHash(void) { return m_uiTypeHash; };
180-
void SetTypeName(const char* szName);
178+
const SString& GetTypeName() { return m_strTypeName; }
179+
unsigned int GetTypeHash() { return m_uiTypeHash; }
180+
void SetTypeName(const SString& name);
181181

182182
CClientEntity* GetParent(void) { return m_pParent; };
183183
CClientEntity* SetParent(CClientEntity* pParent);

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -934,10 +934,12 @@ int CLuaElementDefs::GetElementsWithinRange(lua_State* luaVM)
934934
{
935935
CVector position;
936936
float radius;
937+
SString elementType;
937938

938939
CScriptArgReader argStream(luaVM);
939940
argStream.ReadVector3D(position);
940941
argStream.ReadNumber(radius);
942+
argStream.ReadString(elementType, "");
941943

942944
if (!argStream.HasErrors())
943945
{
@@ -950,9 +952,12 @@ int CLuaElementDefs::GetElementsWithinRange(lua_State* luaVM)
950952

951953
for (CClientEntity* entity : result)
952954
{
953-
lua_pushnumber(luaVM, ++index);
954-
lua_pushelement(luaVM, entity);
955-
lua_settable(luaVM, -3);
955+
if (elementType.empty() || elementType == entity->GetTypeName())
956+
{
957+
lua_pushnumber(luaVM, ++index);
958+
lua_pushelement(luaVM, entity);
959+
lua_settable(luaVM, -3);
960+
}
956961
}
957962

958963
return 1;

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -992,10 +992,12 @@ int CLuaElementDefs::getElementsWithinRange(lua_State* luaVM)
992992
{
993993
CVector position;
994994
float radius;
995+
SString elementType;
995996

996997
CScriptArgReader argStream(luaVM);
997998
argStream.ReadVector3D(position);
998999
argStream.ReadNumber(radius);
1000+
argStream.ReadString(elementType, "");
9991001

10001002
if (!argStream.HasErrors())
10011003
{
@@ -1008,9 +1010,12 @@ int CLuaElementDefs::getElementsWithinRange(lua_State* luaVM)
10081010

10091011
for (CElement* entity : result)
10101012
{
1011-
lua_pushnumber(luaVM, ++index);
1012-
lua_pushelement(luaVM, entity);
1013-
lua_settable(luaVM, -3);
1013+
if (elementType.empty() || elementType == entity->GetTypeName())
1014+
{
1015+
lua_pushnumber(luaVM, ++index);
1016+
lua_pushelement(luaVM, entity);
1017+
lua_settable(luaVM, -3);
1018+
}
10141019
}
10151020

10161021
return 1;

0 commit comments

Comments
 (0)