diff --git a/rwengine/src/engine/GameWorld.cpp b/rwengine/src/engine/GameWorld.cpp index dca0acbb..0ecf92b5 100644 --- a/rwengine/src/engine/GameWorld.cpp +++ b/rwengine/src/engine/GameWorld.cpp @@ -1006,31 +1006,9 @@ bool GameWorld::isRaining() const { void GameWorld::clearObjectsWithinArea(const glm::vec3 center, const float radius, const bool clearParticles) { - bool skipFlag = false; - // Vehicles for (auto& obj : vehiclePool.objects) { - skipFlag = false; - - // Skip if it's the player or owned by player or owned by mission - if (obj.second->getLifetime() == GameObject::PlayerLifetime || - obj.second->getLifetime() == GameObject::MissionLifetime) { - continue; - } - - // Check if we have any important objects in a vehicle, if we do - don't - // erase it - for (auto& seat : - static_cast(obj.second.get())->seatOccupants) { - auto character = static_cast(seat.second); - - if (character->getLifetime() == GameObject::PlayerLifetime || - character->getLifetime() == GameObject::MissionLifetime) { - skipFlag = true; - } - } - - if (skipFlag) { + if (!obj.second->canBeRemoved()) { continue; } @@ -1041,9 +1019,7 @@ void GameWorld::clearObjectsWithinArea(const glm::vec3 center, // Peds for (auto& obj : pedestrianPool.objects) { - // Skip if it's the player or owned by player or owned by mission - if (obj.second->getLifetime() == GameObject::PlayerLifetime || - obj.second->getLifetime() == GameObject::MissionLifetime) { + if (!obj.second->canBeRemoved()) { continue; } diff --git a/rwengine/src/objects/GameObject.hpp b/rwengine/src/objects/GameObject.hpp index cceeeb3b..f6566c2d 100644 --- a/rwengine/src/objects/GameObject.hpp +++ b/rwengine/src/objects/GameObject.hpp @@ -238,10 +238,22 @@ public: void setLifetime(ObjectLifetime ol) { lifetime = ol; } + ObjectLifetime getLifetime() const { return lifetime; } + /// Returns true if the object is not referenced by a script or player + virtual bool canBeRemoved() const { + switch (lifetime) { + case MissionLifetime: + case PlayerLifetime: + return false; + default: + return true; + } + } + virtual void updateTransform(const glm::vec3& pos, const glm::quat& rot) { _lastPosition = position; _lastRotation = rotation; diff --git a/rwengine/src/objects/VehicleObject.cpp b/rwengine/src/objects/VehicleObject.cpp index 1cf810eb..7974c25d 100644 --- a/rwengine/src/objects/VehicleObject.cpp +++ b/rwengine/src/objects/VehicleObject.cpp @@ -643,6 +643,21 @@ float VehicleObject::getVelocity() const { return 0.f; } +bool VehicleObject::canBeRemoved() const { + if (!GameObject::canBeRemoved()) { + return false; + } + + for (auto& seat : seatOccupants) { + auto character = static_cast(seat.second); + + if (!character->canBeRemoved()) + return false; + } + + return true; +} + bool VehicleObject::isWrecked() const { return health < 250.f; } diff --git a/rwengine/src/objects/VehicleObject.hpp b/rwengine/src/objects/VehicleObject.hpp index 1c613f87..39e9933d 100644 --- a/rwengine/src/objects/VehicleObject.hpp +++ b/rwengine/src/objects/VehicleObject.hpp @@ -123,6 +123,8 @@ public: return Vehicle; } + bool canBeRemoved() const override; + bool isWrecked() const; void setHealth(float);