From a644fc107d3dcd42187559b8fdc3720771c18eb8 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Thu, 13 Aug 2015 19:46:30 +0200 Subject: [PATCH] Use +infinity instead of -1 for immediate object destruction --- src/object/interface/damageable_object.h | 8 +++++--- src/object/old_object.cpp | 2 +- src/object/old_object.h | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/object/interface/damageable_object.h b/src/object/interface/damageable_object.h index 672981fe..f0e44d41 100644 --- a/src/object/interface/damageable_object.h +++ b/src/object/interface/damageable_object.h @@ -21,6 +21,8 @@ #include "object/object_interface_type.h" +#include + enum class DamageType { Fire = 1, //!< fire damage (AlienSpider or Shooter), burns on destruction @@ -48,7 +50,7 @@ public: virtual ~CDamageableObject() {} - //! Damage the object, with the given force. Returns true if the object has been fully destroyed (assuming the object is destroyable, of course). force < 0 => destroy immediately (default), force == 0 => default damage values - // NOTE: You should never assume that after this function exits, the object is destroyed, unless it returns true. Even if you specify force = -1, if may still sometimes decide not to destroy the object. - virtual bool DamageObject(DamageType type, float force = -1.0f) = 0; + //! Damage the object, with the given force. Returns true if the object has been fully destroyed (assuming the object is destroyable, of course). force == infinity => destroy immediately (default), force == 0 => default damage values + // NOTE: You should never assume that after this function exits, the object is destroyed, unless it returns true. Even if you specify force = infinity, if may still sometimes decide not to destroy the object. + virtual bool DamageObject(DamageType type, float force = std::numeric_limits::infinity()) = 0; }; diff --git a/src/object/old_object.cpp b/src/object/old_object.cpp index 2ae8697d..223406dd 100644 --- a/src/object/old_object.cpp +++ b/src/object/old_object.cpp @@ -366,7 +366,7 @@ bool COldObject::DamageObject(DamageType type, float force) if (Implements(ObjectInterfaceType::Shielded)) { float magnifyDamage = m_magnifyDamage * m_main->GetGlobalMagnifyDamage(); - if (force >= 0) + if (force != std::numeric_limits::infinity()) { // Calculate the shield lost by the explosion if ( force == 0.0f ) // use default? diff --git a/src/object/old_object.h b/src/object/old_object.h index c21fd924..bbbe9542 100644 --- a/src/object/old_object.h +++ b/src/object/old_object.h @@ -106,7 +106,7 @@ public: void Simplify() override; - bool DamageObject(DamageType type, float force = -1.0f) override; + bool DamageObject(DamageType type, float force = std::numeric_limits::infinity()) override; void DestroyObject(DestructionType type) override; bool EventProcess(const Event& event) override;