Skip to content

Commit 3799b0d

Browse files
Synchronize changes from 1.6 master branch [ci skip]
aa90aa5 Add new function testSphereAgainstWorld (Close #646) (#3787)
2 parents 43074c5 + aa90aa5 commit 3799b0d

File tree

7 files changed

+61
-1
lines changed

7 files changed

+61
-1
lines changed

Client/game_sa/CWorldSA.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,23 @@ bool CWorldSA::ProcessLineOfSight(const CVector* vecStart, const CVector* vecEnd
528528
return bReturn;
529529
}
530530

531+
CEntity* CWorldSA::TestSphereAgainstWorld(const CVector& sphereCenter, float radius, CEntity* ignoredEntity, bool checkBuildings, bool checkVehicles, bool checkPeds, bool checkObjects, bool checkDummies, bool cameraIgnore, STestSphereAgainstWorldResult& result)
532+
{
533+
auto entity = ((CEntitySAInterface*(__cdecl*)(CVector, float, CEntitySAInterface*, bool, bool, bool, bool, bool, bool))FUNC_CWorld_TestSphereAgainstWorld)(sphereCenter, radius, ignoredEntity ? ignoredEntity->GetInterface() : nullptr, checkBuildings, checkVehicles, checkPeds, checkObjects, checkDummies, cameraIgnore);
534+
if (!entity)
535+
return nullptr;
536+
537+
result.collisionDetected = true;
538+
result.modelID = entity->m_nModelIndex;
539+
result.entityPosition = entity->Placeable.matrix->vPos;
540+
ConvertMatrixToEulerAngles(*entity->Placeable.matrix, result.entityRotation.fX, result.entityRotation.fY, result.entityRotation.fZ);
541+
result.entityRotation = -result.entityRotation;
542+
result.lodID = entity->m_pLod ? entity->m_pLod->m_nModelIndex : 0;
543+
result.type = static_cast<eEntityType>(entity->nType);
544+
545+
return pGame->GetPools()->GetEntity(reinterpret_cast<DWORD*>(entity));
546+
}
547+
531548
void CWorldSA::IgnoreEntity(CEntity* pEntity)
532549
{
533550
CEntitySA* pEntitySA = dynamic_cast<CEntitySA*>(pEntity);

Client/game_sa/CWorldSA.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#define VAR_COcclusion_NumActiveOccluders 0xC73CC0
2626
#define CALL_CCullZones_FindTunnelAttributesForCoors 0x55570D
2727
#define FUNC_CWorld_FindPositionForTrackPosition 0x6F59E0
28+
#define FUNC_CWorld_TestSphereAgainstWorld 0x569E20
2829

2930
#define VAR_IgnoredEntity 0xB7CD68
3031
#define VAR_currArea 0xB72914
@@ -74,6 +75,8 @@ class CWorldSA : public CWorld
7475
void ResetAllSurfaceInfo() override;
7576
bool ResetSurfaceInfo(short sSurfaceID) override;
7677

78+
CEntity* TestSphereAgainstWorld(const CVector& sphereCenter, float radius, CEntity* ignoredEntity, bool checkBuildings, bool checkVehicles, bool checkPeds, bool checkObjects, bool checkDummies, bool cameraIgnore, STestSphereAgainstWorldResult& result) override;
79+
7780
private:
7881
float m_fAircraftMaxHeight;
7982
CSurfaceType* m_pSurfaceInfo;

Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,16 @@ ADD_ENUM(PreloadAreaOption::COLLISIONS, "collisions")
910910
ADD_ENUM(PreloadAreaOption::ALL, "all")
911911
IMPLEMENT_ENUM_CLASS_END("preload-area-option")
912912

913+
IMPLEMENT_ENUM_BEGIN(eEntityType)
914+
ADD_ENUM(ENTITY_TYPE_NOTHING, "unknown")
915+
ADD_ENUM(ENTITY_TYPE_BUILDING, "building")
916+
ADD_ENUM(ENTITY_TYPE_VEHICLE, "vehicle")
917+
ADD_ENUM(ENTITY_TYPE_PED, "ped")
918+
ADD_ENUM(ENTITY_TYPE_OBJECT, "object")
919+
ADD_ENUM(ENTITY_TYPE_DUMMY, "dummy")
920+
ADD_ENUM(ENTITY_TYPE_NOTINPOOLS, "unknown")
921+
IMPLEMENT_ENUM_END("entity-type")
922+
913923
//
914924
// CResource from userdata
915925
//

Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ DECLARE_ENUM(ePools);
8888
DECLARE_ENUM(eWorldProperty);
8989
DECLARE_ENUM_CLASS(eModelLoadState);
9090
DECLARE_ENUM_CLASS(PreloadAreaOption);
91+
DECLARE_ENUM(eEntityType);
9192

9293
class CRemoteCall;
9394

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ void CLuaWorldDefs::LoadFunctions()
142142
{"isGarageOpen", IsGarageOpen},
143143
{"isTimeFrozen", ArgumentParser<IsTimeFrozen>},
144144
{"isVolumetricShadowsEnabled", ArgumentParser<IsVolumetricShadowsEnabled>},
145-
{"isDynamicPedShadowsEnabled", ArgumentParser<IsDynamicPedShadowsEnabled>}};
145+
{"isDynamicPedShadowsEnabled", ArgumentParser<IsDynamicPedShadowsEnabled>},
146+
{"testSphereAgainstWorld", ArgumentParser<TestSphereAgainstWorld>}};
146147

147148
// Add functions
148149
for (const auto& [name, func] : functions)
@@ -2297,3 +2298,15 @@ bool CLuaWorldDefs::ResetDynamicPedShadows() noexcept
22972298
{
22982299
return g_pGame->GetSettings()->ResetDynamicPedShadows();
22992300
}
2301+
2302+
CLuaMultiReturn<bool, CClientEntity*, int, float, float, float, float, float, float, int, eEntityType> CLuaWorldDefs::TestSphereAgainstWorld(CVector sphereCenter, float radius, std::optional<CClientEntity*> ignoredEntity, std::optional<bool> checkBuildings, std::optional<bool> checkVehicles, std::optional<bool> checkPeds, std::optional<bool> checkObjects, std::optional<bool> checkDummies, std::optional<bool> cameraIgnore)
2303+
{
2304+
STestSphereAgainstWorldResult result;
2305+
CClientEntity* collidedEntity = nullptr;
2306+
2307+
CEntity* entity = g_pGame->GetWorld()->TestSphereAgainstWorld(sphereCenter, radius, ignoredEntity.has_value() ? ignoredEntity.value()->GetGameEntity() : nullptr, checkBuildings.value_or(true), checkVehicles.value_or(true), checkPeds.value_or(true), checkObjects.value_or(true), checkDummies.value_or(true), cameraIgnore.value_or(false), result);
2308+
if (entity)
2309+
collidedEntity = reinterpret_cast<CClientEntity*>(entity->GetStoredPointer());
2310+
2311+
return {result.collisionDetected, collidedEntity, result.modelID, result.entityPosition.fX, result.entityPosition.fY, result.entityPosition.fZ, ConvertRadiansToDegrees(result.entityRotation.fX), ConvertRadiansToDegrees(result.entityRotation.fY), ConvertRadiansToDegrees(result.entityRotation.fZ), result.lodID, result.type};
2312+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,5 +144,8 @@ class CLuaWorldDefs : public CLuaDefs
144144
static bool SetDynamicPedShadowsEnabled(bool enable);
145145
static bool IsDynamicPedShadowsEnabled() noexcept;
146146
static bool ResetDynamicPedShadows() noexcept;
147+
148+
static CLuaMultiReturn<bool, CClientEntity*, int, float, float, float, float, float, float, int, eEntityType> TestSphereAgainstWorld(CVector sphereCenter, float radius, std::optional<CClientEntity*> ignoredEntity, std::optional<bool> checkBuildings, std::optional<bool> checkVehicles, std::optional<bool> checkPeds, std::optional<bool> checkObjects, std::optional<bool> checkDummies, std::optional<bool> cameraIgnore);
149+
147150
};
148151

Client/sdk/game/CWorld.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*****************************************************************************/
1111

1212
#pragma once
13+
#include "CEntity.h"
1314

1415
class CEntitySAInterface;
1516
class CVector;
@@ -61,6 +62,16 @@ struct SProcessLineOfSightMaterialInfoResult {
6162
bool valid{}; //< Data found in this struct is only valid if this is `true`!
6263
};
6364

65+
struct STestSphereAgainstWorldResult
66+
{
67+
bool collisionDetected{false};
68+
std::uint32_t modelID{0};
69+
CVector entityPosition{};
70+
CVector entityRotation{};
71+
std::uint32_t lodID{0};
72+
eEntityType type{ENTITY_TYPE_NOTHING};
73+
};
74+
6475
enum eDebugCaller
6576
{
6677
CEntity_SetMatrix,
@@ -274,4 +285,6 @@ class CWorld
274285
virtual CSurfaceType* GetSurfaceInfo() = 0;
275286
virtual void ResetAllSurfaceInfo() = 0;
276287
virtual bool ResetSurfaceInfo(short sSurfaceID) = 0;
288+
289+
virtual CEntity* TestSphereAgainstWorld(const CVector& sphereCenter, float radius, CEntity* ignoredEntity, bool checkBuildings, bool checkVehicles, bool checkPeds, bool checkObjects, bool checkDummies, bool cameraIgnore, STestSphereAgainstWorldResult& result) = 0;
277290
};

0 commit comments

Comments
 (0)