mirror of
https://github.com/rwengine/openrw.git
synced 2024-10-06 09:07:19 +02:00
Refactor object removeability check into GameObject
This commit is contained in:
parent
d7c10b1a05
commit
5f01c155e3
@ -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<VehicleObject*>(obj.second.get())->seatOccupants) {
|
||||
auto character = static_cast<CharacterObject*>(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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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<CharacterObject*>(seat.second);
|
||||
|
||||
if (!character->canBeRemoved())
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool VehicleObject::isWrecked() const {
|
||||
return health < 250.f;
|
||||
}
|
||||
|
@ -123,6 +123,8 @@ public:
|
||||
return Vehicle;
|
||||
}
|
||||
|
||||
bool canBeRemoved() const override;
|
||||
|
||||
bool isWrecked() const;
|
||||
|
||||
void setHealth(float);
|
||||
|
Loading…
Reference in New Issue
Block a user