diff options
Diffstat (limited to 'src/entities')
-rw-r--r-- | src/entities/Building.cpp | 22 | ||||
-rw-r--r-- | src/entities/Building.h | 2 | ||||
-rw-r--r-- | src/entities/Dummy.cpp | 15 | ||||
-rw-r--r-- | src/entities/Dummy.h | 2 | ||||
-rw-r--r-- | src/entities/Entity.cpp | 17 | ||||
-rw-r--r-- | src/entities/Entity.h | 2 |
6 files changed, 60 insertions, 0 deletions
diff --git a/src/entities/Building.cpp b/src/entities/Building.cpp index 3c096636..3217e684 100644 --- a/src/entities/Building.cpp +++ b/src/entities/Building.cpp @@ -20,3 +20,25 @@ CBuilding::ReplaceWithNewModel(int32 id) if(m_level == LEVEL_NONE || m_level == CGame::currLevel) CStreaming::RequestModel(id, STREAMFLAGS_DONT_REMOVE); } + +bool +IsBuildingPointerValid(CBuilding* pBuilding) +{ + if (!pBuilding) + return false; + if (pBuilding->GetIsATreadable()) { + int index = CPools::GetTreadablePool()->GetJustIndex((CTreadable*)pBuilding); +#ifdef FIX_BUGS + return index >= 0 && index < CPools::GetTreadablePool()->GetSize(); +#else + return index >= 0 && index <= CPools::GetTreadablePool()->GetSize(); +#endif + } else { + int index = CPools::GetBuildingPool()->GetJustIndex(pBuilding); +#ifdef FIX_BUGS + return index >= 0 && index < CPools::GetBuildingPool()->GetSize(); +#else + return index >= 0 && index <= CPools::GetBuildingPool()->GetSize(); +#endif + } +} diff --git a/src/entities/Building.h b/src/entities/Building.h index 29608c10..2c2dfb1f 100644 --- a/src/entities/Building.h +++ b/src/entities/Building.h @@ -16,3 +16,5 @@ public: virtual bool GetIsATreadable(void) { return false; } }; + +bool IsBuildingPointerValid(CBuilding*); diff --git a/src/entities/Dummy.cpp b/src/entities/Dummy.cpp index 8a4bfd5f..92b69761 100644 --- a/src/entities/Dummy.cpp +++ b/src/entities/Dummy.cpp @@ -50,3 +50,18 @@ CDummy::Remove(void) m_entryInfoList.DeleteNode(node); } } + +bool +IsDummyPointerValid(CDummy* pDummy) +{ + if (!pDummy) + return false; + int index = CPools::GetDummyPool()->GetJustIndex(pDummy); +#ifdef FIX_BUGS + if (index < 0 || index >= CPools::GetDummyPool()->GetSize()) +#else + if (index < 0 || index > CPools::GetDummyPool()->GetSize()) +#endif + return false; + return pDummy->m_entryInfoList.first; +} diff --git a/src/entities/Dummy.h b/src/entities/Dummy.h index 7998a748..84b1ce1a 100644 --- a/src/entities/Dummy.h +++ b/src/entities/Dummy.h @@ -15,3 +15,5 @@ public: static void *operator new(size_t); static void operator delete(void*, size_t); }; + +bool IsDummyPointerValid(CDummy* pDummy); diff --git a/src/entities/Entity.cpp b/src/entities/Entity.cpp index b35ddb25..e83df204 100644 --- a/src/entities/Entity.cpp +++ b/src/entities/Entity.cpp @@ -28,6 +28,8 @@ #include "Bones.h" #include "Debug.h" #include "Renderer.h" +#include "Ped.h" +#include "Dummy.h" int gBuildings; @@ -1028,3 +1030,18 @@ CEntity::LoadEntityFlags(uint8*& buf) } #endif + +bool IsEntityPointerValid(CEntity* pEntity) +{ + if (!pEntity) + return false; + switch (pEntity->GetType()) { + case ENTITY_TYPE_NOTHING: return false; + case ENTITY_TYPE_BUILDING: return IsBuildingPointerValid((CBuilding*)pEntity); + case ENTITY_TYPE_VEHICLE: return IsVehiclePointerValid((CVehicle*)pEntity); + case ENTITY_TYPE_PED: return IsPedPointerValid((CPed*)pEntity); + case ENTITY_TYPE_OBJECT: return IsObjectPointerValid((CObject*)pEntity); + case ENTITY_TYPE_DUMMY: return IsDummyPointerValid((CDummy*)pEntity); + } + return false; +} diff --git a/src/entities/Entity.h b/src/entities/Entity.h index fa57519e..dc5378a5 100644 --- a/src/entities/Entity.h +++ b/src/entities/Entity.h @@ -180,3 +180,5 @@ public: static void AddSteamsFromGround(CPtrList& list); }; + +bool IsEntityPointerValid(CEntity*); |