Skip to content

Commit 076c7fe

Browse files
LpsdPirulax
andauthored
Allow multiple ignored elements to be passed to processLineOfSight (#2032)
Co-authored-by: Pirulax <patrikjankovics7@gmail.com>
1 parent 41492e7 commit 076c7fe

File tree

3 files changed

+49
-16
lines changed

3 files changed

+49
-16
lines changed

Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6311,20 +6311,30 @@ bool CStaticFunctionDefinitions::SetTime(unsigned char ucHour, unsigned char ucM
63116311
}
63126312

63136313
bool CStaticFunctionDefinitions::ProcessLineOfSight(const CVector& vecStart, const CVector& vecEnd, bool& bCollision, CColPoint** pColPoint,
6314-
CClientEntity** pColEntity, const SLineOfSightFlags& flags, CEntity* pIgnoredEntity,
6314+
CClientEntity** pColEntity, const SLineOfSightFlags& flags, std::vector<CClientEntity*> vecIgnoredElements,
63156315
SLineOfSightBuildingResult* pBuildingResult)
63166316
{
63176317
assert(pColPoint);
63186318
assert(pColEntity);
63196319

6320-
if (pIgnoredEntity)
6321-
g_pGame->GetWorld()->IgnoreEntity(pIgnoredEntity);
6320+
vecIgnoredElements.erase(std::remove_if(vecIgnoredElements.begin(), vecIgnoredElements.end(), [](CClientEntity* pIgnoredElement) {
6321+
// Remove entities that already have their colision disabled.
6322+
// This prevents us from re-enabling them.
6323+
if (!CStaticFunctionDefinitions::GetElementCollisionsEnabled(*pIgnoredElement))
6324+
return true;
6325+
6326+
// Otherwise disable collision and keep it in the array
6327+
CStaticFunctionDefinitions::SetElementCollisionsEnabled(*pIgnoredElement, false);
6328+
6329+
return false;
6330+
}), vecIgnoredElements.end());
63226331

63236332
CEntity* pColGameEntity = 0;
63246333
bCollision = g_pGame->GetWorld()->ProcessLineOfSight(&vecStart, &vecEnd, pColPoint, &pColGameEntity, flags, pBuildingResult);
63256334

6326-
if (pIgnoredEntity)
6327-
g_pGame->GetWorld()->IgnoreEntity(NULL);
6335+
// Re-enable collisions
6336+
for (CClientEntity* pIgnoredElement : vecIgnoredElements)
6337+
CStaticFunctionDefinitions::SetElementCollisionsEnabled(*pIgnoredElement, true);
63286338

63296339
CPools* pPools = g_pGame->GetPools();
63306340
*pColEntity = pColGameEntity ? pPools->GetClientEntity((DWORD*)pColGameEntity->GetInterface()) : nullptr;

Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ class CStaticFunctionDefinitions
560560
// World functions
561561
static bool GetTime(unsigned char& ucHour, unsigned char& ucMin);
562562
static bool ProcessLineOfSight(const CVector& vecStart, const CVector& vecEnd, bool& bCollision, CColPoint** pColPoint, CClientEntity** pColEntity,
563-
const SLineOfSightFlags& flags = SLineOfSightFlags(), CEntity* pIgnoredEntity = NULL,
563+
const SLineOfSightFlags& flags = SLineOfSightFlags(), std::vector<CClientEntity*> vecIgnoredElements = {},
564564
SLineOfSightBuildingResult* pBuildingResult = NULL);
565565
static bool IsLineOfSightClear(const CVector& vecStart, const CVector& vecEnd, bool& bIsClear, const SLineOfSightFlags& flags = SLineOfSightFlags(),
566566
CEntity* pIgnoredEntity = NULL);

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

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -232,13 +232,23 @@ int CLuaWorldDefs::ProcessLineOfSight(lua_State* luaVM)
232232
// bool float float float element float float float int int int processLineOfSight ( float startX, float startY, float startZ, float endX, float endY,
233233
// float endZ,
234234
// [ bool checkBuildings = true, bool checkVehicles = true, bool checkPlayers = true, bool checkObjects = true, bool checkDummies = true,
235-
// bool seeThroughStuff = false, bool ignoreSomeObjectsForCamera = false, bool shootThroughStuff = false, element ignoredElement = nil, bool
236-
// returnBuildingInfo = false, bCheckCarTires = false ] )
237-
CVector vecStart;
238-
CVector vecEnd;
239-
SLineOfSightFlags flags;
240-
CClientEntity* pIgnoredElement;
241-
bool bIncludeBuildingInfo;
235+
// bool seeThroughStuff = false, bool ignoreSomeObjectsForCamera = false, bool shootThroughStuff = false, element ignoredElement = nil [,
236+
// element ignoredElement2,
237+
// element ignoredElement3,
238+
// ... etc
239+
// ], bool returnBuildingInfo = false, bCheckCarTires = false ] )
240+
241+
// bool float float float element float float float int int int processLineOfSight ( float startX, float startY, float startZ, float endX, float endY,
242+
// float endZ,
243+
// [ bool checkBuildings = true, bool checkVehicles = true, bool checkPlayers = true, bool checkObjects = true, bool checkDummies = true,
244+
// bool seeThroughStuff = false, bool ignoreSomeObjectsForCamera = false, bool shootThroughStuff = false, table ignoredElements = nil,
245+
// bool returnBuildingInfo = false, bCheckCarTires = false ] )
246+
247+
CVector vecStart;
248+
CVector vecEnd;
249+
SLineOfSightFlags flags;
250+
std::vector<CClientEntity*> vecIgnoredElements;
251+
bool bIncludeBuildingInfo;
242252

243253
CScriptArgReader argStream(luaVM);
244254
argStream.ReadVector3D(vecStart);
@@ -251,18 +261,31 @@ int CLuaWorldDefs::ProcessLineOfSight(lua_State* luaVM)
251261
argStream.ReadBool(flags.bSeeThroughStuff, false);
252262
argStream.ReadBool(flags.bIgnoreSomeObjectsForCamera, false);
253263
argStream.ReadBool(flags.bShootThroughStuff, false);
254-
argStream.ReadUserData(pIgnoredElement, NULL);
264+
265+
if (argStream.NextIsTable()) // Is the next value a table? Read it as a user data table (will error if table contains invalid type)
266+
{
267+
argStream.ReadUserDataTable(vecIgnoredElements);
268+
}
269+
else {
270+
CClientEntity* pIgnoredElement;
271+
argStream.ReadUserData(pIgnoredElement, NULL);
272+
273+
if (pIgnoredElement != NULL)
274+
{
275+
vecIgnoredElements.push_back(pIgnoredElement);
276+
}
277+
}
278+
255279
argStream.ReadBool(bIncludeBuildingInfo, false);
256280
argStream.ReadBool(flags.bCheckCarTires, false);
257281

258282
if (!argStream.HasErrors())
259283
{
260-
CEntity* pIgnoredEntity = pIgnoredElement ? pIgnoredElement->GetGameEntity() : NULL;
261284
CColPoint* pColPoint = NULL;
262285
CClientEntity* pColEntity = NULL;
263286
bool bCollision;
264287
SLineOfSightBuildingResult buildingResult;
265-
if (CStaticFunctionDefinitions::ProcessLineOfSight(vecStart, vecEnd, bCollision, &pColPoint, &pColEntity, flags, pIgnoredEntity,
288+
if (CStaticFunctionDefinitions::ProcessLineOfSight(vecStart, vecEnd, bCollision, &pColPoint, &pColEntity, flags, vecIgnoredElements,
266289
bIncludeBuildingInfo ? &buildingResult : NULL))
267290
{
268291
// Got a collision?

0 commit comments

Comments
 (0)