From a29a4f93ac26c12e0ad4191f501cad9e261c08d7 Mon Sep 17 00:00:00 2001 From: DavivaD Date: Tue, 20 Jun 2017 23:35:33 +0200 Subject: [PATCH] Damage Alert Implementation (2th Stage) --- src/object/interface/damageable_object.h | 7 +++++++ src/object/old_object.cpp | 18 ++++++++++++++++++ src/object/old_object.h | 4 ++++ src/ui/controls/control.h | 3 ++- src/ui/controls/shortcut.cpp | 6 ++++++ src/ui/mainshort.cpp | 1 + 6 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/object/interface/damageable_object.h b/src/object/interface/damageable_object.h index 0813a286..a8f3afb5 100644 --- a/src/object/interface/damageable_object.h +++ b/src/object/interface/damageable_object.h @@ -59,4 +59,11 @@ public: //! Damage the object, with the given force. Returns true if the object has been fully destroyed (assuming the object is destroyable, of course). If force == infinity, destroy immediately (this is the default value) /** 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(), CObject* killer = nullptr) = 0; + + + //! Set the status that means the object is currently taking damage + virtual void SetDamaging(bool damaging) = 0; + //! Is object currently taking damage? + virtual bool IsDamaging() = 0; + }; diff --git a/src/object/old_object.cpp b/src/object/old_object.cpp index dbe92b32..cc0deff6 100644 --- a/src/object/old_object.cpp +++ b/src/object/old_object.cpp @@ -137,6 +137,7 @@ COldObject::COldObject(int id) m_bVirusMode = false; m_virusTime = 0.0f; m_lastVirusParticle = 0.0f; + m_damaging = false; m_dying = DeathType::Alive; m_bFlat = false; m_gunGoalV = 0.0f; @@ -387,6 +388,9 @@ bool COldObject::DamageObject(DamageType type, float force, CObject* killer) float shield = GetShield(); shield -= loss; SetShield(shield); + + // Sending info about taking damage + SetDamaging(true); } else { @@ -394,6 +398,7 @@ bool COldObject::DamageObject(DamageType type, float force, CObject* killer) { // Dead immediately SetShield(0.0f); + SetDamaging(false); } } dead = (GetShield() <= 0.0f); @@ -425,6 +430,9 @@ bool COldObject::DamageObject(DamageType type, float force, CObject* killer) m_engine->GetPyroManager()->Create(Gfx::PT_SHOTT, this, loss); } + /*if ( m_time < 2.0f && m_damaging == true ) SetDamaging(false); + m_time = 0.0f;*/ // TODO: Make DamageAlarm Icon Dissapear after 2 seconds + return false; } @@ -440,6 +448,7 @@ void COldObject::DestroyObject(DestructionType type, CObject* killer) if (Implements(ObjectInterfaceType::Shielded)) { SetShield(0.0f); + SetDamaging(false); } Gfx::PyroType pyroType = Gfx::PT_NULL; @@ -2652,6 +2661,15 @@ float COldObject::GetMagnifyDamage() return m_magnifyDamage; } +void COldObject::SetDamaging(bool damaging) +{ + m_damaging = damaging; +} + +bool COldObject::IsDamaging() +{ + return m_damaging; +} void COldObject::SetDying(DeathType deathType) { diff --git a/src/object/old_object.h b/src/object/old_object.h index 697e05db..da9df205 100644 --- a/src/object/old_object.h +++ b/src/object/old_object.h @@ -237,6 +237,9 @@ public: void SetMagnifyDamage(float factor) override; float GetMagnifyDamage() override; + void SetDamaging(bool damaging); + bool IsDamaging() override; + void SetDying(DeathType deathType) override; DeathType GetDying() override; bool IsDying() override; @@ -356,6 +359,7 @@ protected: bool m_bSelectable; // selectable object bool m_bCheckToken; // object with audited tokens bool m_underground; // object active but undetectable + bool m_damaging; DeathType m_dying; bool m_bFlat; bool m_bTrainer; // drive vehicle (without remote) diff --git a/src/ui/controls/control.h b/src/ui/controls/control.h index 1a193757..b3fb3967 100644 --- a/src/ui/controls/control.h +++ b/src/ui/controls/control.h @@ -57,7 +57,8 @@ enum ControlState STATE_FRAME = (1<<13), // framework highlighting STATE_WARNING = (1<<14), // framework hatched yellow / black STATE_VALUE = (1<<15), // displays the value - STATE_RUN = (1<<16) // running program + STATE_RUN = (1<<16), // running program + STATE_DAMAGE = (1<<17) // taking damage }; diff --git a/src/ui/controls/shortcut.cpp b/src/ui/controls/shortcut.cpp index ef4f5439..fca85862 100644 --- a/src/ui/controls/shortcut.cpp +++ b/src/ui/controls/shortcut.cpp @@ -109,6 +109,12 @@ void CShortcut::Draw() zoom = 1.0f; mode = Gfx::ENG_RSTATE_NORMAL; } + if ( m_state & STATE_DAMAGE ) + { + icon = 59; + zoom = 0.8f; + mode = Gfx::ENG_RSTATE_NORMAL; + } if ( m_icon == 128+6 || m_icon == 128+7 || m_icon == 58 ) // pause or film? { icon = -1; // no bottom diff --git a/src/ui/mainshort.cpp b/src/ui/mainshort.cpp index d9fffa26..23b58ee9 100644 --- a/src/ui/mainshort.cpp +++ b/src/ui/mainshort.cpp @@ -247,6 +247,7 @@ bool CMainShort::UpdateShortcuts() assert(m_shortcuts[i]->Implements(ObjectInterfaceType::Controllable)); pc->SetState(STATE_CHECK, dynamic_cast(m_shortcuts[i])->GetSelect()); pc->SetState(STATE_RUN, m_shortcuts[i]->Implements(ObjectInterfaceType::Programmable) && dynamic_cast(m_shortcuts[i])->IsProgram()); + pc->SetState(STATE_DAMAGE, dynamic_cast(m_shortcuts[i])->IsDamaging()); } } return true;