Skip to content

Allow multiple ignored elements to be passed to processLineOfSight #2032

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6311,20 +6311,30 @@ bool CStaticFunctionDefinitions::SetTime(unsigned char ucHour, unsigned char ucM
}

bool CStaticFunctionDefinitions::ProcessLineOfSight(const CVector& vecStart, const CVector& vecEnd, bool& bCollision, CColPoint** pColPoint,
CClientEntity** pColEntity, const SLineOfSightFlags& flags, CEntity* pIgnoredEntity,
CClientEntity** pColEntity, const SLineOfSightFlags& flags, std::vector<CClientEntity*> vecIgnoredElements,
SLineOfSightBuildingResult* pBuildingResult)
{
assert(pColPoint);
assert(pColEntity);

if (pIgnoredEntity)
g_pGame->GetWorld()->IgnoreEntity(pIgnoredEntity);
vecIgnoredElements.erase(std::remove_if(vecIgnoredElements.begin(), vecIgnoredElements.end(), [](CClientEntity* pIgnoredElement) {
// Remove entities that already have their colision disabled.
// This prevents us from re-enabling them.
if (!CStaticFunctionDefinitions::GetElementCollisionsEnabled(*pIgnoredElement))
return true;

// Otherwise disable collision and keep it in the array
CStaticFunctionDefinitions::SetElementCollisionsEnabled(*pIgnoredElement, false);

return false;
}), vecIgnoredElements.end());

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

if (pIgnoredEntity)
g_pGame->GetWorld()->IgnoreEntity(NULL);
// Re-enable collisions
for (CClientEntity* pIgnoredElement : vecIgnoredElements)
CStaticFunctionDefinitions::SetElementCollisionsEnabled(*pIgnoredElement, true);

CPools* pPools = g_pGame->GetPools();
*pColEntity = pColGameEntity ? pPools->GetClientEntity((DWORD*)pColGameEntity->GetInterface()) : nullptr;
Expand Down
2 changes: 1 addition & 1 deletion Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ class CStaticFunctionDefinitions
// World functions
static bool GetTime(unsigned char& ucHour, unsigned char& ucMin);
static bool ProcessLineOfSight(const CVector& vecStart, const CVector& vecEnd, bool& bCollision, CColPoint** pColPoint, CClientEntity** pColEntity,
const SLineOfSightFlags& flags = SLineOfSightFlags(), CEntity* pIgnoredEntity = NULL,
const SLineOfSightFlags& flags = SLineOfSightFlags(), std::vector<CClientEntity*> vecIgnoredElements = {},
SLineOfSightBuildingResult* pBuildingResult = NULL);
static bool IsLineOfSightClear(const CVector& vecStart, const CVector& vecEnd, bool& bIsClear, const SLineOfSightFlags& flags = SLineOfSightFlags(),
CEntity* pIgnoredEntity = NULL);
Expand Down
43 changes: 33 additions & 10 deletions Client/mods/deathmatch/logic/luadefs/CLuaWorldDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,23 @@ int CLuaWorldDefs::ProcessLineOfSight(lua_State* luaVM)
// bool float float float element float float float int int int processLineOfSight ( float startX, float startY, float startZ, float endX, float endY,
// float endZ,
// [ bool checkBuildings = true, bool checkVehicles = true, bool checkPlayers = true, bool checkObjects = true, bool checkDummies = true,
// bool seeThroughStuff = false, bool ignoreSomeObjectsForCamera = false, bool shootThroughStuff = false, element ignoredElement = nil, bool
// returnBuildingInfo = false, bCheckCarTires = false ] )
CVector vecStart;
CVector vecEnd;
SLineOfSightFlags flags;
CClientEntity* pIgnoredElement;
bool bIncludeBuildingInfo;
// bool seeThroughStuff = false, bool ignoreSomeObjectsForCamera = false, bool shootThroughStuff = false, element ignoredElement = nil [,
// element ignoredElement2,
// element ignoredElement3,
// ... etc
// ], bool returnBuildingInfo = false, bCheckCarTires = false ] )

// bool float float float element float float float int int int processLineOfSight ( float startX, float startY, float startZ, float endX, float endY,
// float endZ,
// [ bool checkBuildings = true, bool checkVehicles = true, bool checkPlayers = true, bool checkObjects = true, bool checkDummies = true,
// bool seeThroughStuff = false, bool ignoreSomeObjectsForCamera = false, bool shootThroughStuff = false, table ignoredElements = nil,
// bool returnBuildingInfo = false, bCheckCarTires = false ] )

CVector vecStart;
CVector vecEnd;
SLineOfSightFlags flags;
std::vector<CClientEntity*> vecIgnoredElements;
bool bIncludeBuildingInfo;

CScriptArgReader argStream(luaVM);
argStream.ReadVector3D(vecStart);
Expand All @@ -251,18 +261,31 @@ int CLuaWorldDefs::ProcessLineOfSight(lua_State* luaVM)
argStream.ReadBool(flags.bSeeThroughStuff, false);
argStream.ReadBool(flags.bIgnoreSomeObjectsForCamera, false);
argStream.ReadBool(flags.bShootThroughStuff, false);
argStream.ReadUserData(pIgnoredElement, NULL);

if (argStream.NextIsTable()) // Is the next value a table? Read it as a user data table (will error if table contains invalid type)
{
argStream.ReadUserDataTable(vecIgnoredElements);
}
else {
CClientEntity* pIgnoredElement;
argStream.ReadUserData(pIgnoredElement, NULL);

if (pIgnoredElement != NULL)
{
vecIgnoredElements.push_back(pIgnoredElement);
}
}

argStream.ReadBool(bIncludeBuildingInfo, false);
argStream.ReadBool(flags.bCheckCarTires, false);

if (!argStream.HasErrors())
{
CEntity* pIgnoredEntity = pIgnoredElement ? pIgnoredElement->GetGameEntity() : NULL;
CColPoint* pColPoint = NULL;
CClientEntity* pColEntity = NULL;
bool bCollision;
SLineOfSightBuildingResult buildingResult;
if (CStaticFunctionDefinitions::ProcessLineOfSight(vecStart, vecEnd, bCollision, &pColPoint, &pColEntity, flags, pIgnoredEntity,
if (CStaticFunctionDefinitions::ProcessLineOfSight(vecStart, vecEnd, bCollision, &pColPoint, &pColEntity, flags, vecIgnoredElements,
bIncludeBuildingInfo ? &buildingResult : NULL))
{
// Got a collision?
Expand Down