From 6510b15704998b14b89fa453ba9d142f85c30dd5 Mon Sep 17 00:00:00 2001 From: Nikolay Korolev Date: Tue, 19 May 2020 01:49:09 +0300 Subject: script revision --- src/entities/Building.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/entities/Building.cpp') 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 + } +} -- cgit v1.2.3