From 63d83185b5eb3cc27e5716722aa78ad5bf977474 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Wed, 12 Aug 2015 00:12:37 +0200 Subject: [PATCH] Move GetTooltipText and Get/SetLock to CObject; remove Get/SetEnable --- src/graphics/engine/pyro.cpp | 4 +-- src/object/auto/auto.cpp | 5 +-- src/object/motion/motionhuman.cpp | 11 ++++-- src/object/object.cpp | 31 +++++++++++++++++ src/object/object.h | 7 ++++ src/object/old_object.cpp | 52 ++--------------------------- src/object/old_object.h | 9 ----- src/object/old_object_interface.cpp | 29 ---------------- src/object/old_object_interface.h | 11 ------ src/object/robotmain.cpp | 14 ++++---- src/object/scene_conditions.cpp | 1 - src/object/task/taskflag.cpp | 3 -- src/physics/physics.cpp | 7 +--- src/ui/mainshort.cpp | 4 +-- src/ui/object_interface.cpp | 4 +-- 15 files changed, 62 insertions(+), 130 deletions(-) diff --git a/src/graphics/engine/pyro.cpp b/src/graphics/engine/pyro.cpp index ea352257..9af79a7e 100644 --- a/src/graphics/engine/pyro.cpp +++ b/src/graphics/engine/pyro.cpp @@ -324,7 +324,7 @@ bool CPyro::Create(PyroType type, CObject* obj, float force) if ( m_type == PT_WPCHECK ) { m_speed = 1.0f/8.0f; - m_object->SetEnable(false); // object more functional + m_object->SetLock(true); // object more functional } if ( m_type == PT_FLCREATE ) { @@ -333,7 +333,7 @@ bool CPyro::Create(PyroType type, CObject* obj, float force) if ( m_type == PT_FLDELETE ) { m_speed = 1.0f/2.0f; - m_object->SetEnable(false); // object more functional + m_object->SetLock(true); // object more functional } if ( m_type == PT_RESET ) { diff --git a/src/object/auto/auto.cpp b/src/object/auto/auto.cpp index e3a76389..e1ed9ea9 100644 --- a/src/object/auto/auto.cpp +++ b/src/object/auto/auto.cpp @@ -192,13 +192,11 @@ bool CAuto::CreateInterface(bool bSelect) pw = static_cast(m_interface->SearchControl(EVENT_WINDOW0)); if ( pw == 0 ) return false; - std::string name; - m_object->GetTooltipName(name); pos.x = 0.0f; pos.y = 64.0f/480.0f; ddim.x = 540.0f/640.0f; ddim.y = 16.0f/480.0f; - pw->CreateLabel(pos, ddim, 0, EVENT_LABEL0, name); + pw->CreateLabel(pos, ddim, 0, EVENT_LABEL0, m_object->GetTooltipText()); dim.x = 33.0f/640.0f; dim.y = 33.0f/480.0f; @@ -442,4 +440,3 @@ bool CAuto::Read(CLevelParserLine* line) return false; } - diff --git a/src/object/motion/motionhuman.cpp b/src/object/motion/motionhuman.cpp index b961f614..ba658839 100644 --- a/src/object/motion/motionhuman.cpp +++ b/src/object/motion/motionhuman.cpp @@ -28,6 +28,7 @@ #include "math/geometry.h" +#include "object/object_manager.h" #include "object/old_object.h" #include "object/robotmain.h" @@ -1382,7 +1383,8 @@ bool CMotionHuman::EventFrame(const Event &event) { if ( m_progress >= 1.0f ) { - m_object->SetEnable(false); + CObjectManager::GetInstancePointer()->DeleteObject(m_object); + return false; } time = 100.0f; @@ -1426,7 +1428,11 @@ bool CMotionHuman::EventFrame(const Event &event) if ( prog >= 1.0f ) { prog = 1.0f; - if ( pos.y >= level ) m_object->SetEnable(false); + if ( pos.y >= level ) + { + CObjectManager::GetInstancePointer()->DeleteObject(m_object); + return false; + } } prog *= 2.0f; @@ -1736,4 +1742,3 @@ void CMotionHuman::StopDisplayPerso() { m_bDisplayPerso = false; } - diff --git a/src/object/object.cpp b/src/object/object.cpp index 3ab7e764..9ce2c90b 100644 --- a/src/object/object.cpp +++ b/src/object/object.cpp @@ -19,6 +19,11 @@ #include "object/object.h" +#include "common/restext.h" +#include "common/stringutils.h" + +#include "object/robotmain.h" + #include "graphics/model/model_crash_sphere.h" #include "script/scriptfunc.h" @@ -35,6 +40,7 @@ CObject::CObject(int id, ObjectType type) , m_team(0) , m_proxyActivate(false) , m_proxyDistance(60.0f) + , m_lock(false) { m_implementedInterfaces.fill(false); m_botVar = CScriptFunctions::CreateObjectVar(this); @@ -269,3 +275,28 @@ CBotVar* CObject::GetBotVar() { return m_botVar; } + +std::string CObject::GetTooltipText() +{ + std::string name; + GetResource(RES_OBJECT, m_type, name); + if (GetTeam() != 0) + { + name += " ["+CRobotMain::GetInstancePointer()->GetTeamName(GetTeam())+" ("+StrUtils::ToString(GetTeam())+")]"; + } + return name; +} + +// Management of the mode "blocked" of an object. +// For example, a cube of titanium is blocked while it is used to make something, +// or a vehicle is blocked as its construction is not finished. + +void CObject::SetLock(bool lock) +{ + m_lock = lock; +} + +bool CObject::GetLock() +{ + return m_lock; +} diff --git a/src/object/object.h b/src/object/object.h index f28ec402..ab7dd59d 100644 --- a/src/object/object.h +++ b/src/object/object.h @@ -181,6 +181,12 @@ public: //! Returns CBot "object" variable associated with this object CBotVar* GetBotVar(); + //! Returns tooltip text for an object + std::string GetTooltipText(); + + void SetLock(bool lock); + bool GetLock(); + protected: //! Transform crash sphere by object's world matrix virtual void TransformCrashSphere(Math::Sphere& crashSphere) = 0; @@ -202,4 +208,5 @@ protected: bool m_proxyActivate; float m_proxyDistance; CBotVar* m_botVar; + bool m_lock; }; diff --git a/src/object/old_object.cpp b/src/object/old_object.cpp index 28a629c5..4b13d29e 100644 --- a/src/object/old_object.cpp +++ b/src/object/old_object.cpp @@ -26,7 +26,6 @@ #include "common/global.h" #include "common/make_unique.h" -#include "common/restext.h" #include "common/stringutils.h" #include "graphics/engine/lightman.h" @@ -142,7 +141,6 @@ COldObject::COldObject(int id) m_bSelectable = true; m_bCheckToken = true; m_bVisible = true; - m_bEnable = true; m_bTrainer = false; m_bToy = false; m_bManual = false; @@ -153,7 +151,6 @@ COldObject::COldObject(int id) m_bVirusMode = false; m_virusTime = 0.0f; m_lastVirusParticle = 0.0f; - m_bLock = false; m_bExplo = false; m_bCargo = false; m_bBurn = false; @@ -767,9 +764,6 @@ void COldObject::Write(CLevelParserLine* line) if ( !GetSelectable() ) line->AddParam("selectable", MakeUnique(GetSelectable())); - if ( !GetEnable() ) - line->AddParam("enable", MakeUnique(GetEnable())); - // TODO: doesn't seem to be used // But it is, this is used by aliens after Thumper ~krzys_h if ( GetFixed() ) @@ -864,7 +858,6 @@ void COldObject::Read(CLevelParserLine* line) SetShield(line->GetParam("shield")->AsFloat(1.0f)); SetRange(line->GetParam("range")->AsFloat(1.0f)); SetSelectable(line->GetParam("selectable")->AsBool(true)); - SetEnable(line->GetParam("enable")->AsBool(true)); SetFixed(line->GetParam("fixed")->AsBool(false)); SetCollisions(line->GetParam("clip")->AsBool(true)); SetLock(line->GetParam("lock")->AsBool(false)); @@ -1994,7 +1987,7 @@ bool COldObject::EventProcess(const Event &event) if ( m_motion != nullptr ) { - m_motion->EventProcess(event); + if (!m_motion->EventProcess(event)) return false; } if ( event.type == EVENT_FRAME ) @@ -2616,23 +2609,6 @@ void COldObject::SetVisible(bool bVisible) } -// Management mode of operation of an object. -// An inactive object is an object destroyed, nonexistent. -// This mode is used for objects "resetables" -// during training to simulate destruction. - -void COldObject::SetEnable(bool bEnable) -{ - m_bEnable = bEnable; -} - -bool COldObject::GetEnable() -{ - return m_bEnable; -} - - - // Management of the method of increasing damage. void COldObject::SetMagnifyDamage(float factor) @@ -2657,19 +2633,7 @@ float COldObject::GetParam() { return m_param; } -// Management of the mode "blocked" of an object. -// For example, a cube of titanium is blocked while it is used to make something, -// or a vehicle is blocked as its construction is not finished. -void COldObject::SetLock(bool bLock) -{ - m_bLock = bLock; -} - -bool COldObject::GetLock() -{ - return m_bLock; -} // Management of the mode "current explosion" of an object. // An object in this mode is not saving. @@ -2719,7 +2683,7 @@ bool COldObject::GetRuin() bool COldObject::GetActive() { - return !m_bLock && !m_bBurn && !m_bFlat && m_bVisible && m_bEnable; + return !GetLock() && !m_bBurn && !m_bFlat && m_bVisible; } @@ -3083,18 +3047,6 @@ int COldObject::GetDefRank() return m_defRank; } -// Getes the object name for the tooltip. - -bool COldObject::GetTooltipName(std::string& name) -{ - GetResource(RES_OBJECT, m_type, name); - if (GetTeam() != 0) - { - name += " ["+CRobotMain::GetInstancePointer()->GetTeamName(GetTeam())+" ("+boost::lexical_cast(GetTeam())+")]"; - } - return !name.empty(); -} - Math::Vector COldObject::GetPosition() const { return GetPartPosition(0); diff --git a/src/object/old_object.h b/src/object/old_object.h index 270948be..59039d9b 100644 --- a/src/object/old_object.h +++ b/src/object/old_object.h @@ -243,9 +243,6 @@ public: void SetVisible(bool bVisible); - void SetEnable(bool bEnable) override; - bool GetEnable() override; - void SetCheckToken(bool bMode); bool GetCheckToken(); @@ -257,8 +254,6 @@ public: void SetExploding(bool bExplo) override; bool IsExploding() override; - void SetLock(bool bLock) override; - bool GetLock() override; void SetBurn(bool bBurn) override; bool GetBurn() override; void SetDead(bool bDead) override; @@ -282,8 +277,6 @@ public: void SetDefRank(int rank) override; int GetDefRank() override; - bool GetTooltipName(std::string& name) override; - bool CreateShadowCircle(float radius, float intensity, Gfx::EngineShadowType type = Gfx::ENG_SHADOW_NORM); bool CreateShadowLight(float height, Gfx::Color color); bool CreateEffectLight(float height, Gfx::Color color); @@ -438,8 +431,6 @@ protected: bool m_bSelectable; // selectable object bool m_bCheckToken; // object with audited tokens bool m_bVisible; // object active but undetectable - bool m_bEnable; // dead object - bool m_bLock; bool m_bExplo; bool m_bCargo; bool m_bBurn; diff --git a/src/object/old_object_interface.cpp b/src/object/old_object_interface.cpp index 7c8b8bd0..5aff4cd0 100644 --- a/src/object/old_object_interface.cpp +++ b/src/object/old_object_interface.cpp @@ -147,19 +147,6 @@ bool COldObjectInterface::GetVirusMode() } -void COldObjectInterface::SetEnable(bool bEnable) -{ - throw std::logic_error("SetEnable: not implemented!"); -} - -bool COldObjectInterface::GetEnable() -{ - // TODO: temporary hack - return true; - //throw std::logic_error("GetEnable: not implemented!"); -} - - void COldObjectInterface::SetMagnifyDamage(float factor) { throw std::logic_error("SetMagnifyDamage: not implemented!"); @@ -194,17 +181,6 @@ bool COldObjectInterface::IsExploding() //throw std::logic_error("IsExploding: not implemented!"); } -void COldObjectInterface::SetLock(bool bLock) -{ - throw std::logic_error("SetLock: not implemented!"); -} - -bool COldObjectInterface::GetLock() -{ - // TODO: temporary hack - return false; - //throw std::logic_error("GetLock: not implemented!"); -} void COldObjectInterface::SetBurn(bool bBurn) { @@ -277,11 +253,6 @@ int COldObjectInterface::GetDefRank() } -bool COldObjectInterface::GetTooltipName(std::string& name) -{ - throw std::logic_error("GetTooltipName: not implemented!"); -} - void COldObjectInterface::FlatParent() { throw std::logic_error("FlatParent: not implemented!"); diff --git a/src/object/old_object_interface.h b/src/object/old_object_interface.h index 516217e3..c70bc9f3 100644 --- a/src/object/old_object_interface.h +++ b/src/object/old_object_interface.h @@ -111,10 +111,6 @@ public: virtual void SetVirusMode(bool bEnable); virtual bool GetVirusMode(); - // Main CObject class? - virtual void SetEnable(bool bEnable); - virtual bool GetEnable(); - // These go to Shielder subclass //! Shielder radius (only while active) [0 or RADIUS_SHIELD_MIN..RADIUS_SHIELD_MAX] virtual float GetShieldRadius(); @@ -134,10 +130,6 @@ public: virtual bool GetRuin(); virtual bool GetActive(); - // probably main CObject? - virtual void SetLock(bool bLock); - virtual bool GetLock(); - // Not sure. CRangedObject? virtual float GetShowLimitRadius(); @@ -151,9 +143,6 @@ public: virtual void SetDefRank(int rank); virtual int GetDefRank(); - // main CObject? not sure - virtual bool GetTooltipName(std::string& name); - // CProgrammableObject or refactor virtual float GetInfoReturn(); }; diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index f30b8947..b18d7d99 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -2204,12 +2204,15 @@ void CRobotMain::HiliteObject(Math::Point pos) if (obj != nullptr) { - std::string objectTooltipName; - if (m_settings->GetTooltips() && obj->GetTooltipName(objectTooltipName)) + if (m_settings->GetTooltips()) { - m_tooltipPos = pos; - m_tooltipName = objectTooltipName; - m_tooltipTime = 0.0f; + std::string objectTooltipName = obj->GetTooltipText(); + if (!objectTooltipName.empty()) + { + m_tooltipPos = pos; + m_tooltipName = objectTooltipName; + m_tooltipTime = 0.0f; + } } if (IsSelectable(obj)) @@ -3620,7 +3623,6 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) bool selectable = line->GetParam("selectable")->AsBool(true); oldObj->SetSelectable(selectable); - oldObj->SetEnable(line->GetParam("enable")->AsBool(true)); oldObj->SetProxyActivate(line->GetParam("proxyActivate")->AsBool(false)); oldObj->SetProxyDistance(line->GetParam("proxyDistance")->AsFloat(15.0f)*g_unit); oldObj->SetRange(line->GetParam("range")->AsFloat(30.0f)); diff --git a/src/object/scene_conditions.cpp b/src/object/scene_conditions.cpp index 8df921dc..3526e362 100644 --- a/src/object/scene_conditions.cpp +++ b/src/object/scene_conditions.cpp @@ -60,7 +60,6 @@ int CSceneCondition::CountObjects() // should be regarded as existing here! if (obj->GetLock()) continue; if (obj->GetRuin()) continue; - if (!obj->GetEnable()) continue; if (!this->countTransported) { diff --git a/src/object/task/taskflag.cpp b/src/object/task/taskflag.cpp index 126bb5cb..37935e55 100644 --- a/src/object/task/taskflag.cpp +++ b/src/object/task/taskflag.cpp @@ -157,8 +157,6 @@ int CTaskFlag::CountObject(ObjectType type) int count = 0; for (CObject* obj : CObjectManager::GetInstancePointer()->GetAllObjects()) { - if ( !obj->GetEnable() ) continue; - ObjectType oType = obj->GetType(); if ( type == OBJECT_NULL ) { @@ -257,4 +255,3 @@ Error CTaskFlag::DeleteFlag() return ERR_OK; } - diff --git a/src/physics/physics.cpp b/src/physics/physics.cpp index ae2e538e..197b7f4e 100644 --- a/src/physics/physics.cpp +++ b/src/physics/physics.cpp @@ -759,8 +759,6 @@ float CPhysics::GetLinLength(float dist) bool CPhysics::EventProcess(const Event &event) { - if ( !m_object->GetEnable() ) return true; - if ( event.type == EVENT_FRAME ) { return EventFrame(event); @@ -2511,7 +2509,6 @@ int CPhysics::ObjectAdapt(const Math::Vector &pos, const Math::Vector &angle) { if ( pObj == m_object ) continue; // yourself? if (IsObjectBeingTransported(pObj)) continue; - if ( !pObj->GetEnable() ) continue; // inactive? if ( pObj->GetRuin() ) continue; // is burning or exploding? if ( pObj->GetDead() ) continue; // dead man? @@ -2556,7 +2553,7 @@ int CPhysics::ObjectAdapt(const Math::Vector &pos, const Math::Vector &angle) } if ( oType == OBJECT_WAYPOINT && - pObj->GetEnable() && + !pObj->GetLock() && m_object->GetTrainer() ) // driving vehicle? { Math::Vector oPos = pObj->GetPosition(); @@ -2724,8 +2721,6 @@ bool CPhysics::JostleObject(CObject* pObj, float force) bool CPhysics::ExploOther(ObjectType iType, CObject *pObj, ObjectType oType, float force) { - if ( !pObj->GetEnable() ) return true; - JostleObject(pObj, 1.0f); // shakes the object if ( force > 50.0f && diff --git a/src/ui/mainshort.cpp b/src/ui/mainshort.cpp index 46ea9e22..f6e2e94f 100644 --- a/src/ui/mainshort.cpp +++ b/src/ui/mainshort.cpp @@ -153,9 +153,7 @@ bool CMainShort::CreateShortcuts() positions[teamIndex].x += dim.x; m_shortcuts.push_back(pObj); - std::string tooltipName; - pObj->GetTooltipName(tooltipName); - shortcut->SetTooltip(tooltipName); + shortcut->SetTooltip(pObj->GetTooltipText()); rank ++; diff --git a/src/ui/object_interface.cpp b/src/ui/object_interface.cpp index 14404a76..f3cd6aef 100644 --- a/src/ui/object_interface.cpp +++ b/src/ui/object_interface.cpp @@ -833,14 +833,12 @@ bool CObjectInterface::CreateInterface(bool bSelect) pw = static_cast< CWindow* >(m_interface->SearchControl(EVENT_WINDOW0)); if ( pw == 0 ) return false; - std::string tooltipLabel; - m_object->GetTooltipName(tooltipLabel); pos.x = 0.0f; pos.y = 64.0f/480.0f; ddim.x = 540.0f/640.0f; if ( !m_main->GetShowMap() ) ddim.x = 640.0f/640.0f; ddim.y = 16.0f/480.0f; - pw->CreateLabel(pos, ddim, 0, EVENT_LABEL0, tooltipLabel); + pw->CreateLabel(pos, ddim, 0, EVENT_LABEL0, m_object->GetTooltipText()); dim.x = 33.0f/640.0f; dim.y = 33.0f/480.0f;