From e11d2ec33ea381a878686b82282771b99d935013 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 16 Aug 2015 20:24:48 +0200 Subject: [PATCH] Refactor object dying status and GetActive --- src/graphics/engine/lightning.cpp | 2 +- src/graphics/engine/particle.cpp | 4 +- src/graphics/engine/pyro.cpp | 16 ++-- src/level/robotmain.cpp | 20 ++--- src/level/scene_conditions.cpp | 5 +- src/object/auto/autoradar.cpp | 2 +- src/object/auto/autotower.cpp | 2 +- .../implementation/programmable_impl.cpp | 2 +- src/object/interface/destroyable_object.h | 15 ++++ src/object/motion/motionant.cpp | 11 +-- src/object/motion/motionbee.cpp | 19 +++-- src/object/motion/motionhuman.cpp | 6 +- src/object/motion/motionqueen.cpp | 3 +- src/object/motion/motionspider.cpp | 11 +-- src/object/motion/motionvehicle.cpp | 3 +- src/object/motion/motionworm.cpp | 5 +- src/object/object_manager.cpp | 2 +- src/object/old_object.cpp | 77 +++++++------------ src/object/old_object.h | 20 ++--- src/object/old_object_interface.cpp | 53 ++----------- src/object/old_object_interface.h | 12 +-- src/object/task/taskgoto.cpp | 2 +- src/object/task/taskmanip.cpp | 2 +- src/object/task/tasktake.cpp | 2 +- src/physics/physics.cpp | 39 +++++----- src/ui/controls/map.cpp | 2 +- src/ui/controls/target.cpp | 2 +- src/ui/mainshort.cpp | 4 +- 28 files changed, 146 insertions(+), 197 deletions(-) diff --git a/src/graphics/engine/lightning.cpp b/src/graphics/engine/lightning.cpp index c27e44d0..04eb37ae 100644 --- a/src/graphics/engine/lightning.cpp +++ b/src/graphics/engine/lightning.cpp @@ -322,7 +322,7 @@ CObject* CLightning::SearchObject(Math::Vector pos) float min = 100000.0f; for (CObject* obj : CObjectManager::GetInstancePointer()->GetAllObjects()) { - if (!obj->GetActive()) continue; // inactive object? + if (!obj->GetDetectable()) continue; // inactive object? if (IsObjectBeingTransported(obj)) continue; diff --git a/src/graphics/engine/particle.cpp b/src/graphics/engine/particle.cpp index cb0fd0bb..ce872b48 100644 --- a/src/graphics/engine/particle.cpp +++ b/src/graphics/engine/particle.cpp @@ -3580,7 +3580,7 @@ CObject* CParticle::SearchObjectGun(Math::Vector old, Math::Vector pos, bool shield = false; for (CObject* obj : CObjectManager::GetInstancePointer()->GetAllObjects()) { - if (!obj->GetActive()) continue; // inactive? + if (!obj->GetDetectable()) continue; // inactive? if (obj == father) continue; ObjectType oType = obj->GetType(); @@ -3677,7 +3677,7 @@ CObject* CParticle::SearchObjectRay(Math::Vector pos, Math::Vector goal, for (CObject* obj : CObjectManager::GetInstancePointer()->GetAllObjects()) { - if (!obj->GetActive()) continue; // inactive? + if (!obj->GetDetectable()) continue; // inactive? if (obj == father) continue; ObjectType oType = obj->GetType(); diff --git a/src/graphics/engine/pyro.cpp b/src/graphics/engine/pyro.cpp index 565693aa..3d451456 100644 --- a/src/graphics/engine/pyro.cpp +++ b/src/graphics/engine/pyro.cpp @@ -262,7 +262,8 @@ bool CPyro::Create(PyroType type, CObject* obj, float force) if ( m_type == PT_DEADG ) { - m_object->SetDead(true); + assert(m_object->Implements(ObjectInterfaceType::Destroyable)); + dynamic_cast(m_object)->SetDying(DeathType::Dead); assert(obj->Implements(ObjectInterfaceType::Movable)); dynamic_cast(obj)->GetMotion()->SetAction(MHS_DEADg, 1.0f); @@ -274,7 +275,8 @@ bool CPyro::Create(PyroType type, CObject* obj, float force) } if ( m_type == PT_DEADW ) { - m_object->SetDead(true); + assert(m_object->Implements(ObjectInterfaceType::Destroyable)); + dynamic_cast(m_object)->SetDying(DeathType::Dead); assert(obj->Implements(ObjectInterfaceType::Movable)); dynamic_cast(obj)->GetMotion()->SetAction(MHS_DEADw, 1.0f); @@ -1530,7 +1532,8 @@ void CPyro::ExploStart() m_object->Simplify(); m_object->SetLock(true); // ruin not usable yet - m_object->SetExploding(true); // being destroyed + assert(m_object->Implements(ObjectInterfaceType::Destroyable)); + dynamic_cast(m_object)->SetDying(DeathType::Exploding); // being destroyed m_object->FlatParent(); if ( m_object->Implements(ObjectInterfaceType::Controllable) && dynamic_cast(m_object)->GetSelect() ) @@ -2172,12 +2175,13 @@ void CPyro::BurnTerminate() m_object->SetLock(false); } - m_object->SetBurn(false); // ruin usable (c-e-d. recoverable) + assert(m_object->Implements(ObjectInterfaceType::Destroyable)); + dynamic_cast(m_object)->SetDying(DeathType::Alive); // ruin usable (c-e-d. recoverable) } void CPyro::FallStart() { - m_object->SetBurn(true); // usable + m_object->SetLock(true); // usable Math::Vector pos = m_object->GetPosition(); m_fallFloor = m_terrain->GetFloorLevel(pos); @@ -2308,7 +2312,7 @@ Error CPyro::FallIsEnded() if (pos.y > m_fallFloor) return ERR_CONTINUE; m_sound->Play(SOUND_BOUM, pos); - m_object->SetBurn(false); // usable again + m_object->SetLock(false); // usable again return ERR_STOP; } diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index d9754b15..4e215599 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -1864,13 +1864,13 @@ CObject* CRobotMain::DetectObject(Math::Point pos) for (CObject* obj : m_objMan->GetAllObjects()) { - if (!obj->GetActive()) continue; + if (!obj->GetDetectable()) continue; CObject* transporter = nullptr; if (obj->Implements(ObjectInterfaceType::Transportable)) transporter = dynamic_cast(obj)->GetTransporter(); - if (transporter != nullptr && !transporter->GetActive()) continue; + if (transporter != nullptr && !transporter->GetDetectable()) continue; if (obj->GetProxyActivate()) continue; CObject* target = obj; @@ -1881,6 +1881,7 @@ CObject* CRobotMain::DetectObject(Math::Point pos) if (target == nullptr) target = obj; // standalone battery } + if (!obj->Implements(ObjectInterfaceType::Old)) continue; for (int j = 0; j < OBJECTMAXPART; j++) { int rank = obj->GetObjectRank(j); @@ -3884,7 +3885,7 @@ float CRobotMain::SearchNearestObject(Math::Vector center, CObject *exclu) float min = 100000.0f; for (CObject* obj : m_objMan->GetAllObjects()) { - if (!obj->GetActive()) continue; // inactive? + if (!obj->GetDetectable()) continue; // inactive? if (IsObjectBeingTransported(obj)) continue; if (obj == exclu) continue; @@ -4106,7 +4107,7 @@ void CRobotMain::ShowDropZone(CObject* metal, CObject* transporter) float tMax; for (CObject* obj : m_objMan->GetAllObjects()) { - if (!obj->GetActive()) continue; // inactive? + if (!obj->GetDetectable()) continue; // inactive? if (IsObjectBeingTransported(obj)) continue; if (obj == metal) continue; @@ -4547,9 +4548,7 @@ bool CRobotMain::IOWriteScene(std::string filename, std::string filecbot, std::s if (obj->GetType() == OBJECT_TOTO) continue; if (obj->GetType() == OBJECT_FIX) continue; if (IsObjectBeingTransported(obj)) continue; - if (obj->GetBurn()) continue; - if (obj->GetDead()) continue; - if (obj->IsExploding()) continue; + if (obj->Implements(ObjectInterfaceType::Destroyable) && dynamic_cast(obj)->IsDying()) continue; if (obj->Implements(ObjectInterfaceType::Carrier)) { @@ -4603,9 +4602,7 @@ bool CRobotMain::IOWriteScene(std::string filename, std::string filecbot, std::s if (obj->GetType() == OBJECT_TOTO) continue; if (obj->GetType() == OBJECT_FIX) continue; if (IsObjectBeingTransported(obj)) continue; - - if (obj->GetBurn()) continue; - if (obj->GetDead()) continue; + if (obj->Implements(ObjectInterfaceType::Destroyable) && dynamic_cast(obj)->IsDying()) continue; if (!SaveFileStack(obj, file, objRank++)) break; } @@ -4801,8 +4798,7 @@ CObject* CRobotMain::IOReadScene(std::string filename, std::string filecbot) if (obj->GetType() == OBJECT_TOTO) continue; if (obj->GetType() == OBJECT_FIX) continue; if (IsObjectBeingTransported(obj)) continue; - if (obj->GetBurn()) continue; - if (obj->GetDead()) continue; + if (obj->Implements(ObjectInterfaceType::Destroyable) && dynamic_cast(obj)->IsDying()) continue; if (!ReadFileStack(obj, file, objRank++)) break; } diff --git a/src/level/scene_conditions.cpp b/src/level/scene_conditions.cpp index df294756..09f5e9d6 100644 --- a/src/level/scene_conditions.cpp +++ b/src/level/scene_conditions.cpp @@ -56,10 +56,7 @@ int CSceneCondition::CountObjects() int nb = 0; for (CObject* obj : CObjectManager::GetInstancePointer()->GetAllObjects()) { - // Do not use GetActive () because an invisible worm (underground) - // should be regarded as existing here! - if (obj->GetLock()) continue; - if (obj->GetRuin()) continue; + if (!obj->GetActive()) continue; if (!this->countTransported) { diff --git a/src/object/auto/autoradar.cpp b/src/object/auto/autoradar.cpp index c9510717..083fa807 100644 --- a/src/object/auto/autoradar.cpp +++ b/src/object/auto/autoradar.cpp @@ -273,7 +273,7 @@ bool CAutoRadar::SearchEnemy(Math::Vector &pos) CObject* best = nullptr; for (CObject* obj : CObjectManager::GetInstancePointer()->GetAllObjects()) { - if ( !obj->GetActive() ) continue; + if ( !obj->GetDetectable() ) continue; ObjectType oType = obj->GetType(); if ( oType != OBJECT_ANT && diff --git a/src/object/auto/autotower.cpp b/src/object/auto/autotower.cpp index 0bdab8d7..2b6007b1 100644 --- a/src/object/auto/autotower.cpp +++ b/src/object/auto/autotower.cpp @@ -278,7 +278,7 @@ CObject* CAutoTower::SearchTarget(Math::Vector &impact) oType != OBJECT_BEE && oType != OBJECT_WORM ) continue; - if ( !obj->GetActive() ) continue; // inactive? + if ( !obj->GetDetectable() ) continue; // inactive? //? if ( g_researchDone & RESEARCH_QUICK ) if ( false ) diff --git a/src/object/implementation/programmable_impl.cpp b/src/object/implementation/programmable_impl.cpp index 8976ebd9..7f4e6565 100644 --- a/src/object/implementation/programmable_impl.cpp +++ b/src/object/implementation/programmable_impl.cpp @@ -65,7 +65,7 @@ bool CProgrammableObjectImpl::EventProcess(const Event &event) { if (event.type == EVENT_FRAME) { - if ( m_object->GetRuin() && IsProgram() ) + if ( m_object->Implements(ObjectInterfaceType::Destroyable) && dynamic_cast(m_object)->IsDying() && IsProgram() ) { StopProgram(); } diff --git a/src/object/interface/destroyable_object.h b/src/object/interface/destroyable_object.h index 2c6bbe92..32a53d01 100644 --- a/src/object/interface/destroyable_object.h +++ b/src/object/interface/destroyable_object.h @@ -30,6 +30,14 @@ enum class DestructionType Drowned = 4, //!< drowned (only for Me) }; +enum class DeathType +{ + Alive = -1, //!< not dead + Exploding, //!< killed by explosion + Burning, //!< killed by fire + Dead //!< dead human +}; + /** * \class CDestroyableObject * \brief Interface for objects that can be destroyed @@ -53,4 +61,11 @@ public: //! Returns the distance modifier for CLightning, used to modify hit probability. Value in range [0..1], where 0 is never and 1 is normal probability virtual float GetLightningHitProbability() = 0; + + //! Set the status that means the object is currently dying + virtual void SetDying(DeathType deathType) = 0; + //! Return object death type + virtual DeathType GetDying() = 0; + //! Is object currently dying? + virtual bool IsDying() = 0; }; diff --git a/src/object/motion/motionant.cpp b/src/object/motion/motionant.cpp index b46b7639..f96da8dc 100644 --- a/src/object/motion/motionant.cpp +++ b/src/object/motion/motionant.cpp @@ -424,11 +424,8 @@ bool CMotionAnt::EventFrame(const Event &event) m_armMember += a; } - if ( m_object->GetRuin() ) // destroyed? - { - m_actionType = MAS_RUIN; - } - if ( m_object->GetBurn() ) // burning? + assert(m_object->Implements(ObjectInterfaceType::Destroyable)); + if ( dynamic_cast(m_object)->GetDying() == DeathType::Burning ) // burning? { if ( m_object->GetFixed() ) { @@ -439,6 +436,10 @@ bool CMotionAnt::EventFrame(const Event &event) m_actionType = -1; } } + else if ( dynamic_cast(m_object)->IsDying() ) // destroyed? + { + m_actionType = MAS_RUIN; + } for ( i=0 ; i<6 ; i++ ) // the six legs { diff --git a/src/object/motion/motionbee.cpp b/src/object/motion/motionbee.cpp index 20829026..06a47d43 100644 --- a/src/object/motion/motionbee.cpp +++ b/src/object/motion/motionbee.cpp @@ -403,14 +403,15 @@ bool CMotionBee::EventFrame(const Event &event) m_actionType = -1; if (IsObjectCarryingCargo(m_object)) m_actionType = MBS_HOLD; // carries the ball - if ( m_object->GetRuin() ) // destroyed? - { - m_actionType = MBS_RUIN; - } - if ( m_object->GetBurn() ) // burning? + assert(m_object->Implements(ObjectInterfaceType::Destroyable)); + if ( dynamic_cast(m_object)->GetDying() == DeathType::Burning ) // burning? { m_actionType = MBS_BURN; } + else if ( dynamic_cast(m_object)->IsDying() ) // destroyed? + { + m_actionType = MBS_RUIN; + } for ( i=0 ; i<6 ; i++ ) // the six legs { @@ -473,14 +474,12 @@ bool CMotionBee::EventFrame(const Event &event) if ( m_physics->GetLand() ) // on the ground? { - if ( m_object->GetRuin() ) - { - } - else if ( bStop || m_object->GetBurn() ) + assert(m_object->Implements(ObjectInterfaceType::Destroyable)); + if ( bStop || dynamic_cast(m_object)->GetDying() == DeathType::Burning ) { m_object->SetPartRotationZ(2, sinf(m_armTimeAbs*1.7f)*0.15f+0.35f); // tail } - else + if ( !dynamic_cast(m_object)->IsDying() ) { a = Math::Mod(m_armTimeMarch, 1.0f); if ( a < 0.5f ) a = -1.0f+4.0f*a; // -1..1 diff --git a/src/object/motion/motionhuman.cpp b/src/object/motion/motionhuman.cpp index f1a93bab..83cd9045 100644 --- a/src/object/motion/motionhuman.cpp +++ b/src/object/motion/motionhuman.cpp @@ -1462,6 +1462,7 @@ bool CMotionHuman::EventFrame(const Event &event) } } + assert(m_object->Implements(ObjectInterfaceType::Destroyable)); // Management of the head. if ( m_actionType == MHS_TAKE || // takes? m_actionType == MHS_FLAG ) // takes? @@ -1491,10 +1492,7 @@ bool CMotionHuman::EventFrame(const Event &event) m_object->SetPartRotationX(1, sinf(m_armTimeAbs*0.7f)*0.10f); m_object->SetPartRotationY(1, sinf(m_armTimeAbs*3.0f)*0.30f*factor); } - else if ( m_object->GetDead() ) // dead? - { - } - else + else if ( !dynamic_cast(m_object)->IsDying() ) // dead? { m_object->SetPartRotationZ(1, Math::Smooth(m_object->GetPartRotationZ(1), sinf(m_armTimeAbs*1.0f)*0.2f, event.rTime*5.0f)); m_object->SetPartRotationX(1, sinf(m_armTimeAbs*1.1f)*0.1f); diff --git a/src/object/motion/motionqueen.cpp b/src/object/motion/motionqueen.cpp index a1f8df5b..1c829cac 100644 --- a/src/object/motion/motionqueen.cpp +++ b/src/object/motion/motionqueen.cpp @@ -392,7 +392,8 @@ bool CMotionQueen::EventFrame(const Event &event) } } - if ( !bStop && !m_object->GetRuin() ) + assert(m_object->Implements(ObjectInterfaceType::Destroyable)); + if ( !bStop && !dynamic_cast(m_object)->IsDying() ) { a = Math::Mod(m_armTimeMarch, 1.0f); if ( a < 0.5f ) a = -1.0f+4.0f*a; // -1..1 diff --git a/src/object/motion/motionspider.cpp b/src/object/motion/motionspider.cpp index d1feef71..8bad1264 100644 --- a/src/object/motion/motionspider.cpp +++ b/src/object/motion/motionspider.cpp @@ -359,11 +359,8 @@ bool CMotionSpider::EventFrame(const Event &event) m_armMember += a; } - if ( m_object->GetRuin() ) // destroyed? - { - m_actionType = MSS_RUIN; - } - if ( m_object->GetBurn() ) // burning? + assert(m_object->Implements(ObjectInterfaceType::Destroyable)); + if (dynamic_cast(m_object)->GetDying() == DeathType::Burning ) // burning? { if ( m_object->GetFixed() ) { @@ -374,6 +371,10 @@ bool CMotionSpider::EventFrame(const Event &event) m_actionType = -1; } } + else if ( dynamic_cast(m_object)->IsDying() ) // destroyed? + { + m_actionType = MSS_RUIN; + } for ( i=0 ; i<8 ; i++ ) // the 8 legs { diff --git a/src/object/motion/motionvehicle.cpp b/src/object/motion/motionvehicle.cpp index d06fdbb0..390a627b 100644 --- a/src/object/motion/motionvehicle.cpp +++ b/src/object/motion/motionvehicle.cpp @@ -1677,7 +1677,8 @@ bool CMotionVehicle::EventFrameInsect(const Event &event) m_armMember += a; } - if ( m_object->GetRuin() ) // burn or explode? + assert(m_object->Implements(ObjectInterfaceType::Destroyable)); + if ( dynamic_cast(m_object)->IsDying() ) // burn or explode? { action = 3; } diff --git a/src/object/motion/motionworm.cpp b/src/object/motion/motionworm.cpp index 12cfe099..acdda32c 100644 --- a/src/object/motion/motionworm.cpp +++ b/src/object/motion/motionworm.cpp @@ -250,6 +250,7 @@ bool CMotionWorm::EventFrame(const Event &event) m_armTimeAbs += event.rTime; m_armTimeMarch += event.rTime*m_armLinSpeed; + assert(m_object->Implements(ObjectInterfaceType::Destroyable)); under = 0; // no piece under the ground for ( i=0 ; iGetBurn() ) // is burning? + if ( dynamic_cast(m_object)->IsDying() ) // is burning? { h = 0.0f; // remains on earth } h += 0.3f; height[i] = h; } - m_object->SetVisible(under!=WORM_PART+2); + m_object->SetUnderground(under == WORM_PART+2); if ( !m_engine->IsVisiblePoint(m_object->GetPosition()) ) return true; diff --git a/src/object/object_manager.cpp b/src/object/object_manager.cpp index 826ebf0c..d6cac4c8 100644 --- a/src/object/object_manager.cpp +++ b/src/object/object_manager.cpp @@ -273,7 +273,7 @@ CObject* CObjectManager::Radar(CObject* pThis, Math::Vector thisPosition, float if (pObj == nullptr) continue; if (IsObjectBeingTransported(pObj)) continue; - if ( !pObj->GetActive() ) continue; + if ( !pObj->GetDetectable() ) continue; if ( pObj->GetProxyActivate() ) continue; oType = pObj->GetType(); diff --git a/src/object/old_object.cpp b/src/object/old_object.cpp index 2f350598..bd1af553 100644 --- a/src/object/old_object.cpp +++ b/src/object/old_object.cpp @@ -130,7 +130,7 @@ COldObject::COldObject(int id) m_bSelect = false; m_bSelectable = true; m_bCheckToken = true; - m_bVisible = true; + m_underground = false; m_bTrainer = false; m_bToy = false; m_bManual = false; @@ -140,10 +140,8 @@ COldObject::COldObject(int id) m_bVirusMode = false; m_virusTime = 0.0f; m_lastVirusParticle = 0.0f; - m_bExplo = false; m_bCargo = false; - m_bBurn = false; - m_bDead = false; + m_dying = DeathType::Alive; m_bFlat = false; m_gunGoalV = 0.0f; m_gunGoalH = 0.0f; @@ -339,7 +337,7 @@ bool COldObject::DamageObject(DamageType type, float force) assert(Implements(ObjectInterfaceType::Damageable)); assert(!Implements(ObjectInterfaceType::Destroyable) || Implements(ObjectInterfaceType::Shielded) || Implements(ObjectInterfaceType::Fragile)); - if ( m_bDead ) return false; + if ( IsDying() ) return false; if ( m_type == OBJECT_ANT || m_type == OBJECT_WORM || @@ -438,7 +436,7 @@ void COldObject::DestroyObject(DestructionType type) if(type == DestructionType::NoEffect) assert(!!"DestructionType::NoEffect should not be passed to DestroyObject()!"); assert(type != DestructionType::Drowned || m_type == OBJECT_HUMAN); - if ( m_bDead ) return; + if ( IsDying() ) return; if (Implements(ObjectInterfaceType::Shielded)) { @@ -511,7 +509,7 @@ void COldObject::DestroyObject(DestructionType type) m_type == OBJECT_BULLET ) { pyroType = Gfx::PT_BURNO; - SetBurn(true); + SetDying(DeathType::Burning); } else if ( m_type == OBJECT_HUMAN ) { @@ -520,7 +518,7 @@ void COldObject::DestroyObject(DestructionType type) else { pyroType = Gfx::PT_BURNT; - SetBurn(true); + SetDying(DeathType::Burning); } SetVirusMode(false); } @@ -1147,7 +1145,8 @@ void COldObject::Read(CLevelParserLine* line) SetGunGoalV(line->GetParam("aimV")->AsFloat(0.0f)); SetGunGoalH(line->GetParam("aimH")->AsFloat(0.0f)); - m_bBurn = line->GetParam("burnMode")->AsBool(false); + if (line->GetParam("burnMode")->AsBool(false)) + SetDying(DeathType::Burning); m_bVirusMode = line->GetParam("virusMode")->AsBool(false); m_virusTime = line->GetParam("virusTime")->AsFloat(0.0f); @@ -2032,7 +2031,7 @@ bool COldObject::EventProcess(const Event &event) m_type != OBJECT_SPIDER && m_type != OBJECT_BEE ) { - if ( !m_bDead ) m_camera->SetType(Gfx::CAM_TYPE_EXPLO); + if ( !IsDying() ) m_camera->SetType(Gfx::CAM_TYPE_EXPLO); m_main->DeselectAll(); } return false; @@ -2056,7 +2055,7 @@ bool COldObject::EventProcess(const Event &event) float axeX = 0.0f; float axeY = 0.0f; float axeZ = 0.0f; - if ( m_bBurn ) // Gifted? + if ( GetDying() == DeathType::Burning ) // Burning? { axeZ = -1.0f; // tomb @@ -2198,7 +2197,7 @@ bool COldObject::EventFrame(const Event &event) if ( m_engine->GetPause() && m_type != OBJECT_SHOW ) return true; - if ( m_bBurn ) m_burnTime += event.rTime; + if ( GetDying() == DeathType::Burning ) m_burnTime += event.rTime; m_aTime += event.rTime; m_shotTime += event.rTime; @@ -2749,13 +2748,11 @@ bool COldObject::GetCheckToken() } -// Management of the visibility of an object. -// The object is not hidden or visually disabled, but ignores detections! -// For example: underground worm. +// Sets if this object is underground or not. Underground objects are not detectable. Used by AlienWorm -void COldObject::SetVisible(bool bVisible) +void COldObject::SetUnderground(bool underground) { - m_bVisible = bVisible; + m_underground = underground; } @@ -2785,55 +2782,35 @@ float COldObject::GetParam() } -// Management of the mode "current explosion" of an object. -// An object in this mode is not saving. - -void COldObject::SetExploding(bool bExplo) +void COldObject::SetDying(DeathType deathType) { - m_bExplo = bExplo; -} - -bool COldObject::IsExploding() -{ - return m_bExplo; -} - -// Management of the HS mode of an object. - -void COldObject::SetBurn(bool bBurn) -{ - m_bBurn = bBurn; + m_dying = deathType; m_burnTime = 0.0f; -} -bool COldObject::GetBurn() -{ - return m_bBurn; -} - -void COldObject::SetDead(bool bDead) -{ - m_bDead = bDead; - - if ( bDead && Implements(ObjectInterfaceType::Programmable) ) + if ( IsDying() && Implements(ObjectInterfaceType::Programmable) ) { StopProgram(); // stops the current task } } -bool COldObject::GetDead() +DeathType COldObject::GetDying() { - return m_bDead; + return m_dying; } -bool COldObject::GetRuin() +bool COldObject::IsDying() { - return m_bBurn|m_bFlat; + return m_dying != DeathType::Alive; } bool COldObject::GetActive() { - return !GetLock() && !m_bBurn && !m_bFlat && m_bVisible; + return !GetLock() && !IsDying() && !m_bFlat; +} + +bool COldObject::GetDetectable() +{ + return GetActive() && !m_underground; } diff --git a/src/object/old_object.h b/src/object/old_object.h index bbd99e80..ebc2e6b7 100644 --- a/src/object/old_object.h +++ b/src/object/old_object.h @@ -234,7 +234,7 @@ public: void SetSelectable(bool bMode); bool GetSelectable() override; - void SetVisible(bool bVisible); + void SetUnderground(bool underground); void SetCheckToken(bool bMode); bool GetCheckToken(); @@ -245,14 +245,12 @@ public: void SetParam(float value) override; float GetParam() override; - void SetExploding(bool bExplo) override; - bool IsExploding() override; - void SetBurn(bool bBurn) override; - bool GetBurn() override; - void SetDead(bool bDead) override; - bool GetDead() override; - bool GetRuin() override; + void SetDying(DeathType deathType) override; + DeathType GetDying() override; + bool IsDying() override; + bool GetActive() override; + bool GetDetectable() override; void SetGunGoalV(float gunGoal); void SetGunGoalH(float gunGoal); @@ -358,11 +356,9 @@ protected: bool m_bSelect; // object selected bool m_bSelectable; // selectable object bool m_bCheckToken; // object with audited tokens - bool m_bVisible; // object active but undetectable - bool m_bExplo; + bool m_underground; // object active but undetectable bool m_bCargo; - bool m_bBurn; - bool m_bDead; + DeathType m_dying; bool m_bFlat; bool m_bTrainer; // drive vehicle (without remote) bool m_bToy; // toy key diff --git a/src/object/old_object_interface.cpp b/src/object/old_object_interface.cpp index cc966b89..61e4caa5 100644 --- a/src/object/old_object_interface.cpp +++ b/src/object/old_object_interface.cpp @@ -135,57 +135,20 @@ float COldObjectInterface::GetParam() } -void COldObjectInterface::SetExploding(bool bExplo) -{ - throw std::logic_error("SetExploding: not implemented!"); -} - -bool COldObjectInterface::IsExploding() -{ - // TODO: temporary hack - return false; - //throw std::logic_error("IsExploding: not implemented!"); -} - - -void COldObjectInterface::SetBurn(bool bBurn) -{ - throw std::logic_error("SetBurn: not implemented!"); -} - -bool COldObjectInterface::GetBurn() -{ - // TODO: temporary hack - return false; - //throw std::logic_error("GetBurn: not implemented!"); -} - -void COldObjectInterface::SetDead(bool bDead) -{ - throw std::logic_error("SetDead: not implemented!"); -} - -bool COldObjectInterface::GetDead() -{ - // TODO: temporary hack - return false; - //throw std::logic_error("GetDead: not implemented!"); -} - -bool COldObjectInterface::GetRuin() -{ - // TODO: temporary hack - return false; - //throw std::logic_error("GetRuin: not implemented!"); -} - bool COldObjectInterface::GetActive() { // TODO: temporary hack - return false; + return true; //throw std::logic_error("GetActive: not implemented!"); } +bool COldObjectInterface::GetDetectable() +{ + // TODO: temporary hack + return true; + //throw std::logic_error("GetDetectable: not implemented!"); +} + CAuto* COldObjectInterface::GetAuto() { diff --git a/src/object/old_object_interface.h b/src/object/old_object_interface.h index dfebd28b..b9b7391d 100644 --- a/src/object/old_object_interface.h +++ b/src/object/old_object_interface.h @@ -102,15 +102,11 @@ public: virtual float GetParam(); //@} - // TODO: What to do with these? - virtual void SetExploding(bool bExplo); - virtual bool IsExploding(); - virtual void SetBurn(bool bBurn); - virtual bool GetBurn(); - virtual void SetDead(bool bDead); - virtual bool GetDead(); - virtual bool GetRuin(); + // Main CObject? + //! Is this object active (not dead)? virtual bool GetActive(); + //! Is this object detectable (not dead and not underground)? + virtual bool GetDetectable(); // This will be eventually removed after refactoring to subclasses virtual CAuto* GetAuto(); diff --git a/src/object/task/taskgoto.cpp b/src/object/task/taskgoto.cpp index ef7ac2b9..c47a97d2 100644 --- a/src/object/task/taskgoto.cpp +++ b/src/object/task/taskgoto.cpp @@ -1271,7 +1271,7 @@ bool CTaskGoto::LeakSearch(Math::Vector &pos, float &delay) for (CObject* obj : CObjectManager::GetInstancePointer()->GetAllObjects()) { if ( obj == m_object ) continue; - if ( !obj->GetActive() ) continue; + if ( !obj->GetDetectable() ) continue; if (IsObjectBeingTransported(obj)) continue; for (const auto& objCrashSphere : obj->GetAllCrashSpheres()) diff --git a/src/object/task/taskmanip.cpp b/src/object/task/taskmanip.cpp index d55f0fb3..ebf760d4 100644 --- a/src/object/task/taskmanip.cpp +++ b/src/object/task/taskmanip.cpp @@ -1258,7 +1258,7 @@ bool CTaskManip::IsFreeDeposeObject(Math::Vector pos) for (CObject* obj : CObjectManager::GetInstancePointer()->GetAllObjects()) { if ( obj == m_object ) continue; - if ( !obj->GetActive() ) continue; // inactive? + if ( !obj->GetDetectable() ) continue; // inactive? if (IsObjectBeingTransported(obj)) continue; for (const auto& crashSphere : obj->GetAllCrashSpheres()) diff --git a/src/object/task/tasktake.cpp b/src/object/task/tasktake.cpp index 4993bfdf..5b0ccb6c 100644 --- a/src/object/task/tasktake.cpp +++ b/src/object/task/tasktake.cpp @@ -561,7 +561,7 @@ bool CTaskTake::IsFreeDeposeObject(Math::Vector pos) for (CObject* pObj : CObjectManager::GetInstancePointer()->GetAllObjects()) { if ( pObj == m_object ) continue; - if ( !pObj->GetActive() ) continue; // inactive? + if ( !pObj->GetDetectable() ) continue; // inactive? if (IsObjectBeingTransported(pObj)) continue; for (const auto& crashSphere : pObj->GetAllCrashSpheres()) diff --git a/src/physics/physics.cpp b/src/physics/physics.cpp index 8bb7de56..06e93a03 100644 --- a/src/physics/physics.cpp +++ b/src/physics/physics.cpp @@ -818,7 +818,7 @@ void CPhysics::MotorUpdate(float aTime, float rTime) } } - if ( m_object->GetDead() ) // dead man? + if ( m_object->GetType() == OBJECT_HUMAN && dynamic_cast(m_object)->GetDying() == DeathType::Dead ) // dead man? { motorSpeed.x = 0.0f; motorSpeed.z = 0.0f; @@ -1455,7 +1455,7 @@ bool CPhysics::EventFrame(const Event &event) iAngle = angle = m_object->GetRotation(); // Accelerate is the descent, brake is the ascent. - if ( m_bFreeze || m_object->GetDead() ) + if ( m_bFreeze || (m_object->Implements(ObjectInterfaceType::Destroyable) && dynamic_cast(m_object)->IsDying()) ) { m_linMotion.terrainSpeed.x = 0.0f; m_linMotion.terrainSpeed.z = 0.0f; @@ -1594,7 +1594,7 @@ void CPhysics::SoundMotor(float rTime) if ( type == OBJECT_MOTHER ) { - if ( m_lastSoundInsect <= 0.0f && m_object->GetActive() ) + if ( m_lastSoundInsect <= 0.0f && m_object->GetDetectable() ) { m_sound->Play(SOUND_INSECTm, m_object->GetPosition()); if ( m_bMotor ) m_lastSoundInsect = 0.4f+Math::Rand()*2.5f; @@ -1603,7 +1603,8 @@ void CPhysics::SoundMotor(float rTime) } else if ( type == OBJECT_ANT ) { - if ( m_object->GetBurn() || + assert(m_object->Implements(ObjectInterfaceType::Destroyable)); + if ( dynamic_cast(m_object)->GetDying() == DeathType::Burning || m_object->GetFixed() ) { if ( m_lastSoundInsect <= 0.0f ) @@ -1612,7 +1613,7 @@ void CPhysics::SoundMotor(float rTime) m_lastSoundInsect = 0.4f+Math::Rand()*0.6f; } } - else if ( m_object->GetActive() ) + else if ( m_object->GetDetectable() ) { if ( m_lastSoundInsect <= 0.0f ) { @@ -1624,7 +1625,8 @@ void CPhysics::SoundMotor(float rTime) } else if ( type == OBJECT_BEE ) { - if ( m_object->GetActive() ) + assert(m_object->Implements(ObjectInterfaceType::Destroyable)); + if ( m_object->GetDetectable() ) { if ( m_lastSoundInsect <= 0.0f ) { @@ -1633,7 +1635,7 @@ void CPhysics::SoundMotor(float rTime) else m_lastSoundInsect = 1.5f+Math::Rand()*4.0f; } } - else if ( m_object->GetBurn() ) + else if ( dynamic_cast(m_object)->GetDying() == DeathType::Burning ) { if ( m_lastSoundInsect <= 0.0f ) { @@ -1644,7 +1646,8 @@ void CPhysics::SoundMotor(float rTime) } else if ( type == OBJECT_WORM ) { - if ( m_object->GetActive() ) + assert(m_object->Implements(ObjectInterfaceType::Destroyable)); + if ( m_object->GetDetectable() ) { if ( m_lastSoundInsect <= 0.0f ) { @@ -1653,7 +1656,7 @@ void CPhysics::SoundMotor(float rTime) else m_lastSoundInsect = 1.5f+Math::Rand()*4.0f; } } - else if ( m_object->GetBurn() ) + else if ( dynamic_cast(m_object)->GetDying() == DeathType::Burning ) { if ( m_lastSoundInsect <= 0.0f ) { @@ -1664,7 +1667,8 @@ void CPhysics::SoundMotor(float rTime) } else if ( type == OBJECT_SPIDER ) { - if ( m_object->GetBurn() || + assert(m_object->Implements(ObjectInterfaceType::Destroyable)); + if ( dynamic_cast(m_object)->GetDying() == DeathType::Burning || m_object->GetFixed() ) { if ( m_lastSoundInsect <= 0.0f ) @@ -1673,7 +1677,7 @@ void CPhysics::SoundMotor(float rTime) m_lastSoundInsect = 0.4f+Math::Rand()*0.6f; } } - else if ( m_object->GetActive() ) + else if ( m_object->GetDetectable() ) { if ( m_lastSoundInsect <= 0.0f ) { @@ -1687,7 +1691,7 @@ void CPhysics::SoundMotor(float rTime) { if ( !m_object->Implements(ObjectInterfaceType::Flying) ) { - if ( m_bMotor && m_object->GetActive() ) + if ( m_bMotor && m_object->GetDetectable() ) { SoundMotorFull(rTime, type); // full diet } @@ -1710,7 +1714,7 @@ void CPhysics::SoundMotor(float rTime) if ( m_object->Implements(ObjectInterfaceType::Flying) ) { if ( m_bMotor && !m_bSwim && - m_object->GetActive() && !m_object->GetDead() ) + m_object->GetDetectable() ) { SoundReactorFull(rTime, type); // full diet } @@ -1774,7 +1778,7 @@ void CPhysics::WaterFrame(float aTime, float rTime) if ( type == OBJECT_TOTO ) return; if ( type == OBJECT_NULL ) return; - if ( !m_object->GetActive() ) return; + if ( !m_object->GetDetectable() ) return; if (type == OBJECT_HUMAN && m_object->GetOption() != 0 ) // human without a helmet?) { @@ -2468,7 +2472,7 @@ int CPhysics::ObjectAdapt(const Math::Vector &pos, const Math::Vector &angle) int colType; ObjectType iType, oType; - if ( m_object->GetRuin() ) return 0; // is burning or exploding? + if ( m_object->Implements(ObjectInterfaceType::Destroyable) && dynamic_cast(m_object)->IsDying() ) return 0; // is burning or exploding? if ( !m_object->GetCollisions() ) return 0; // iiPos = sphere center is the old position. @@ -2487,8 +2491,7 @@ int CPhysics::ObjectAdapt(const Math::Vector &pos, const Math::Vector &angle) { if ( pObj == m_object ) continue; // yourself? if (IsObjectBeingTransported(pObj)) continue; - if ( pObj->GetRuin() ) continue; // is burning or exploding? - if ( pObj->GetDead() ) continue; // dead man? + if ( pObj->Implements(ObjectInterfaceType::Destroyable) && dynamic_cast(pObj)->IsDying() ) continue; // is burning or exploding? oType = pObj->GetType(); if ( oType == OBJECT_NULL ) continue; @@ -3443,7 +3446,7 @@ void CPhysics::MotorParticle(float aTime, float rTime) if ( (type == OBJECT_HUMAN || type == OBJECT_TECH) && m_bSwim ) { - if ( !m_object->GetDead() ) + if ( !m_object->Implements(ObjectInterfaceType::Destroyable) || dynamic_cast(m_object)->GetDying() != DeathType::Dead ) { h = Math::Mod(aTime, 5.0f); if ( h < 3.5f && ( h < 1.5f || h > 1.6f ) ) return; diff --git a/src/ui/controls/map.cpp b/src/ui/controls/map.cpp index 86595f9b..6aba8f59 100644 --- a/src/ui/controls/map.cpp +++ b/src/ui/controls/map.cpp @@ -1147,7 +1147,7 @@ void CMap::UpdateObject(CObject* pObj) if ( !m_bEnable ) return; if ( m_totalFix >= m_totalMove ) return; // full table? - if ( !pObj->GetActive() ) return; + if ( !pObj->GetDetectable() ) return; if ( pObj->Implements(ObjectInterfaceType::Controllable) && !dynamic_cast(pObj)->GetSelectable() ) return; if ( pObj->GetProxyActivate() ) return; if (IsObjectBeingTransported(pObj)) return; diff --git a/src/ui/controls/target.cpp b/src/ui/controls/target.cpp index 2e0c30f7..1d05c3f5 100644 --- a/src/ui/controls/target.cpp +++ b/src/ui/controls/target.cpp @@ -140,7 +140,7 @@ CObject* CTarget::DetectFriendObject(Math::Point pos) for (CObject* obj : CObjectManager::GetInstancePointer()->GetAllObjects()) { - if ( !obj->GetActive() ) continue; + if ( !obj->GetDetectable() ) continue; if ( obj->GetProxyActivate() ) continue; if ( obj->Implements(ObjectInterfaceType::Controllable) && dynamic_cast(obj)->GetSelect() ) continue; diff --git a/src/ui/mainshort.cpp b/src/ui/mainshort.cpp index 33029714..3d6cd92b 100644 --- a/src/ui/mainshort.cpp +++ b/src/ui/mainshort.cpp @@ -123,7 +123,7 @@ bool CMainShort::CreateShortcuts() std::vector teams; for (CObject* object : CObjectManager::GetInstancePointer()->GetAllObjects()) { - if (!object->GetActive()) + if (!object->GetDetectable()) continue; if(GetShortcutIcon(object->GetType()) == -1) @@ -144,7 +144,7 @@ bool CMainShort::CreateShortcuts() int rank = 0; for (CObject* pObj : CObjectManager::GetInstancePointer()->GetAllObjects()) { - if ( !pObj->GetActive() ) continue; + if ( !pObj->GetDetectable() ) continue; if ( pObj->Implements(ObjectInterfaceType::Controllable) && !dynamic_cast(pObj)->GetSelectable() ) continue; if ( pObj->GetProxyActivate() ) continue;