Move GetTooltipText and Get/SetLock to CObject; remove Get/SetEnable

master
krzys-h 2015-08-12 00:12:37 +02:00
parent f37d2a338e
commit 63d83185b5
15 changed files with 62 additions and 130 deletions

View File

@ -324,7 +324,7 @@ bool CPyro::Create(PyroType type, CObject* obj, float force)
if ( m_type == PT_WPCHECK ) if ( m_type == PT_WPCHECK )
{ {
m_speed = 1.0f/8.0f; 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 ) if ( m_type == PT_FLCREATE )
{ {
@ -333,7 +333,7 @@ bool CPyro::Create(PyroType type, CObject* obj, float force)
if ( m_type == PT_FLDELETE ) if ( m_type == PT_FLDELETE )
{ {
m_speed = 1.0f/2.0f; 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 ) if ( m_type == PT_RESET )
{ {

View File

@ -192,13 +192,11 @@ bool CAuto::CreateInterface(bool bSelect)
pw = static_cast<Ui::CWindow*>(m_interface->SearchControl(EVENT_WINDOW0)); pw = static_cast<Ui::CWindow*>(m_interface->SearchControl(EVENT_WINDOW0));
if ( pw == 0 ) return false; if ( pw == 0 ) return false;
std::string name;
m_object->GetTooltipName(name);
pos.x = 0.0f; pos.x = 0.0f;
pos.y = 64.0f/480.0f; pos.y = 64.0f/480.0f;
ddim.x = 540.0f/640.0f; ddim.x = 540.0f/640.0f;
ddim.y = 16.0f/480.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.x = 33.0f/640.0f;
dim.y = 33.0f/480.0f; dim.y = 33.0f/480.0f;
@ -442,4 +440,3 @@ bool CAuto::Read(CLevelParserLine* line)
return false; return false;
} }

View File

@ -28,6 +28,7 @@
#include "math/geometry.h" #include "math/geometry.h"
#include "object/object_manager.h"
#include "object/old_object.h" #include "object/old_object.h"
#include "object/robotmain.h" #include "object/robotmain.h"
@ -1382,7 +1383,8 @@ bool CMotionHuman::EventFrame(const Event &event)
{ {
if ( m_progress >= 1.0f ) if ( m_progress >= 1.0f )
{ {
m_object->SetEnable(false); CObjectManager::GetInstancePointer()->DeleteObject(m_object);
return false;
} }
time = 100.0f; time = 100.0f;
@ -1426,7 +1428,11 @@ bool CMotionHuman::EventFrame(const Event &event)
if ( prog >= 1.0f ) if ( prog >= 1.0f )
{ {
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; prog *= 2.0f;
@ -1736,4 +1742,3 @@ void CMotionHuman::StopDisplayPerso()
{ {
m_bDisplayPerso = false; m_bDisplayPerso = false;
} }

View File

@ -19,6 +19,11 @@
#include "object/object.h" #include "object/object.h"
#include "common/restext.h"
#include "common/stringutils.h"
#include "object/robotmain.h"
#include "graphics/model/model_crash_sphere.h" #include "graphics/model/model_crash_sphere.h"
#include "script/scriptfunc.h" #include "script/scriptfunc.h"
@ -35,6 +40,7 @@ CObject::CObject(int id, ObjectType type)
, m_team(0) , m_team(0)
, m_proxyActivate(false) , m_proxyActivate(false)
, m_proxyDistance(60.0f) , m_proxyDistance(60.0f)
, m_lock(false)
{ {
m_implementedInterfaces.fill(false); m_implementedInterfaces.fill(false);
m_botVar = CScriptFunctions::CreateObjectVar(this); m_botVar = CScriptFunctions::CreateObjectVar(this);
@ -269,3 +275,28 @@ CBotVar* CObject::GetBotVar()
{ {
return m_botVar; 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<int>(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;
}

View File

@ -181,6 +181,12 @@ public:
//! Returns CBot "object" variable associated with this object //! Returns CBot "object" variable associated with this object
CBotVar* GetBotVar(); CBotVar* GetBotVar();
//! Returns tooltip text for an object
std::string GetTooltipText();
void SetLock(bool lock);
bool GetLock();
protected: protected:
//! Transform crash sphere by object's world matrix //! Transform crash sphere by object's world matrix
virtual void TransformCrashSphere(Math::Sphere& crashSphere) = 0; virtual void TransformCrashSphere(Math::Sphere& crashSphere) = 0;
@ -202,4 +208,5 @@ protected:
bool m_proxyActivate; bool m_proxyActivate;
float m_proxyDistance; float m_proxyDistance;
CBotVar* m_botVar; CBotVar* m_botVar;
bool m_lock;
}; };

View File

@ -26,7 +26,6 @@
#include "common/global.h" #include "common/global.h"
#include "common/make_unique.h" #include "common/make_unique.h"
#include "common/restext.h"
#include "common/stringutils.h" #include "common/stringutils.h"
#include "graphics/engine/lightman.h" #include "graphics/engine/lightman.h"
@ -142,7 +141,6 @@ COldObject::COldObject(int id)
m_bSelectable = true; m_bSelectable = true;
m_bCheckToken = true; m_bCheckToken = true;
m_bVisible = true; m_bVisible = true;
m_bEnable = true;
m_bTrainer = false; m_bTrainer = false;
m_bToy = false; m_bToy = false;
m_bManual = false; m_bManual = false;
@ -153,7 +151,6 @@ COldObject::COldObject(int id)
m_bVirusMode = false; m_bVirusMode = false;
m_virusTime = 0.0f; m_virusTime = 0.0f;
m_lastVirusParticle = 0.0f; m_lastVirusParticle = 0.0f;
m_bLock = false;
m_bExplo = false; m_bExplo = false;
m_bCargo = false; m_bCargo = false;
m_bBurn = false; m_bBurn = false;
@ -767,9 +764,6 @@ void COldObject::Write(CLevelParserLine* line)
if ( !GetSelectable() ) if ( !GetSelectable() )
line->AddParam("selectable", MakeUnique<CLevelParserParam>(GetSelectable())); line->AddParam("selectable", MakeUnique<CLevelParserParam>(GetSelectable()));
if ( !GetEnable() )
line->AddParam("enable", MakeUnique<CLevelParserParam>(GetEnable()));
// TODO: doesn't seem to be used // TODO: doesn't seem to be used
// But it is, this is used by aliens after Thumper ~krzys_h // But it is, this is used by aliens after Thumper ~krzys_h
if ( GetFixed() ) if ( GetFixed() )
@ -864,7 +858,6 @@ void COldObject::Read(CLevelParserLine* line)
SetShield(line->GetParam("shield")->AsFloat(1.0f)); SetShield(line->GetParam("shield")->AsFloat(1.0f));
SetRange(line->GetParam("range")->AsFloat(1.0f)); SetRange(line->GetParam("range")->AsFloat(1.0f));
SetSelectable(line->GetParam("selectable")->AsBool(true)); SetSelectable(line->GetParam("selectable")->AsBool(true));
SetEnable(line->GetParam("enable")->AsBool(true));
SetFixed(line->GetParam("fixed")->AsBool(false)); SetFixed(line->GetParam("fixed")->AsBool(false));
SetCollisions(line->GetParam("clip")->AsBool(true)); SetCollisions(line->GetParam("clip")->AsBool(true));
SetLock(line->GetParam("lock")->AsBool(false)); SetLock(line->GetParam("lock")->AsBool(false));
@ -1994,7 +1987,7 @@ bool COldObject::EventProcess(const Event &event)
if ( m_motion != nullptr ) if ( m_motion != nullptr )
{ {
m_motion->EventProcess(event); if (!m_motion->EventProcess(event)) return false;
} }
if ( event.type == EVENT_FRAME ) 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. // Management of the method of increasing damage.
void COldObject::SetMagnifyDamage(float factor) void COldObject::SetMagnifyDamage(float factor)
@ -2657,19 +2633,7 @@ float COldObject::GetParam()
{ {
return m_param; 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. // Management of the mode "current explosion" of an object.
// An object in this mode is not saving. // An object in this mode is not saving.
@ -2719,7 +2683,7 @@ bool COldObject::GetRuin()
bool COldObject::GetActive() 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; 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<std::string>(GetTeam())+")]";
}
return !name.empty();
}
Math::Vector COldObject::GetPosition() const Math::Vector COldObject::GetPosition() const
{ {
return GetPartPosition(0); return GetPartPosition(0);

View File

@ -243,9 +243,6 @@ public:
void SetVisible(bool bVisible); void SetVisible(bool bVisible);
void SetEnable(bool bEnable) override;
bool GetEnable() override;
void SetCheckToken(bool bMode); void SetCheckToken(bool bMode);
bool GetCheckToken(); bool GetCheckToken();
@ -257,8 +254,6 @@ public:
void SetExploding(bool bExplo) override; void SetExploding(bool bExplo) override;
bool IsExploding() override; bool IsExploding() override;
void SetLock(bool bLock) override;
bool GetLock() override;
void SetBurn(bool bBurn) override; void SetBurn(bool bBurn) override;
bool GetBurn() override; bool GetBurn() override;
void SetDead(bool bDead) override; void SetDead(bool bDead) override;
@ -282,8 +277,6 @@ public:
void SetDefRank(int rank) override; void SetDefRank(int rank) override;
int GetDefRank() override; int GetDefRank() override;
bool GetTooltipName(std::string& name) override;
bool CreateShadowCircle(float radius, float intensity, Gfx::EngineShadowType type = Gfx::ENG_SHADOW_NORM); bool CreateShadowCircle(float radius, float intensity, Gfx::EngineShadowType type = Gfx::ENG_SHADOW_NORM);
bool CreateShadowLight(float height, Gfx::Color color); bool CreateShadowLight(float height, Gfx::Color color);
bool CreateEffectLight(float height, Gfx::Color color); bool CreateEffectLight(float height, Gfx::Color color);
@ -438,8 +431,6 @@ protected:
bool m_bSelectable; // selectable object bool m_bSelectable; // selectable object
bool m_bCheckToken; // object with audited tokens bool m_bCheckToken; // object with audited tokens
bool m_bVisible; // object active but undetectable bool m_bVisible; // object active but undetectable
bool m_bEnable; // dead object
bool m_bLock;
bool m_bExplo; bool m_bExplo;
bool m_bCargo; bool m_bCargo;
bool m_bBurn; bool m_bBurn;

View File

@ -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) void COldObjectInterface::SetMagnifyDamage(float factor)
{ {
throw std::logic_error("SetMagnifyDamage: not implemented!"); throw std::logic_error("SetMagnifyDamage: not implemented!");
@ -194,17 +181,6 @@ bool COldObjectInterface::IsExploding()
//throw std::logic_error("IsExploding: not implemented!"); //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) 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() void COldObjectInterface::FlatParent()
{ {
throw std::logic_error("FlatParent: not implemented!"); throw std::logic_error("FlatParent: not implemented!");

View File

@ -111,10 +111,6 @@ public:
virtual void SetVirusMode(bool bEnable); virtual void SetVirusMode(bool bEnable);
virtual bool GetVirusMode(); virtual bool GetVirusMode();
// Main CObject class?
virtual void SetEnable(bool bEnable);
virtual bool GetEnable();
// These go to Shielder subclass // These go to Shielder subclass
//! Shielder radius (only while active) [0 or RADIUS_SHIELD_MIN..RADIUS_SHIELD_MAX] //! Shielder radius (only while active) [0 or RADIUS_SHIELD_MIN..RADIUS_SHIELD_MAX]
virtual float GetShieldRadius(); virtual float GetShieldRadius();
@ -134,10 +130,6 @@ public:
virtual bool GetRuin(); virtual bool GetRuin();
virtual bool GetActive(); virtual bool GetActive();
// probably main CObject?
virtual void SetLock(bool bLock);
virtual bool GetLock();
// Not sure. CRangedObject? // Not sure. CRangedObject?
virtual float GetShowLimitRadius(); virtual float GetShowLimitRadius();
@ -151,9 +143,6 @@ public:
virtual void SetDefRank(int rank); virtual void SetDefRank(int rank);
virtual int GetDefRank(); virtual int GetDefRank();
// main CObject? not sure
virtual bool GetTooltipName(std::string& name);
// CProgrammableObject or refactor // CProgrammableObject or refactor
virtual float GetInfoReturn(); virtual float GetInfoReturn();
}; };

View File

@ -2204,12 +2204,15 @@ void CRobotMain::HiliteObject(Math::Point pos)
if (obj != nullptr) if (obj != nullptr)
{ {
std::string objectTooltipName; if (m_settings->GetTooltips())
if (m_settings->GetTooltips() && obj->GetTooltipName(objectTooltipName))
{ {
m_tooltipPos = pos; std::string objectTooltipName = obj->GetTooltipText();
m_tooltipName = objectTooltipName; if (!objectTooltipName.empty())
m_tooltipTime = 0.0f; {
m_tooltipPos = pos;
m_tooltipName = objectTooltipName;
m_tooltipTime = 0.0f;
}
} }
if (IsSelectable(obj)) if (IsSelectable(obj))
@ -3620,7 +3623,6 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
bool selectable = line->GetParam("selectable")->AsBool(true); bool selectable = line->GetParam("selectable")->AsBool(true);
oldObj->SetSelectable(selectable); oldObj->SetSelectable(selectable);
oldObj->SetEnable(line->GetParam("enable")->AsBool(true));
oldObj->SetProxyActivate(line->GetParam("proxyActivate")->AsBool(false)); oldObj->SetProxyActivate(line->GetParam("proxyActivate")->AsBool(false));
oldObj->SetProxyDistance(line->GetParam("proxyDistance")->AsFloat(15.0f)*g_unit); oldObj->SetProxyDistance(line->GetParam("proxyDistance")->AsFloat(15.0f)*g_unit);
oldObj->SetRange(line->GetParam("range")->AsFloat(30.0f)); oldObj->SetRange(line->GetParam("range")->AsFloat(30.0f));

View File

@ -60,7 +60,6 @@ int CSceneCondition::CountObjects()
// should be regarded as existing here! // should be regarded as existing here!
if (obj->GetLock()) continue; if (obj->GetLock()) continue;
if (obj->GetRuin()) continue; if (obj->GetRuin()) continue;
if (!obj->GetEnable()) continue;
if (!this->countTransported) if (!this->countTransported)
{ {

View File

@ -157,8 +157,6 @@ int CTaskFlag::CountObject(ObjectType type)
int count = 0; int count = 0;
for (CObject* obj : CObjectManager::GetInstancePointer()->GetAllObjects()) for (CObject* obj : CObjectManager::GetInstancePointer()->GetAllObjects())
{ {
if ( !obj->GetEnable() ) continue;
ObjectType oType = obj->GetType(); ObjectType oType = obj->GetType();
if ( type == OBJECT_NULL ) if ( type == OBJECT_NULL )
{ {
@ -257,4 +255,3 @@ Error CTaskFlag::DeleteFlag()
return ERR_OK; return ERR_OK;
} }

View File

@ -759,8 +759,6 @@ float CPhysics::GetLinLength(float dist)
bool CPhysics::EventProcess(const Event &event) bool CPhysics::EventProcess(const Event &event)
{ {
if ( !m_object->GetEnable() ) return true;
if ( event.type == EVENT_FRAME ) if ( event.type == EVENT_FRAME )
{ {
return EventFrame(event); 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 ( pObj == m_object ) continue; // yourself?
if (IsObjectBeingTransported(pObj)) continue; if (IsObjectBeingTransported(pObj)) continue;
if ( !pObj->GetEnable() ) continue; // inactive?
if ( pObj->GetRuin() ) continue; // is burning or exploding? if ( pObj->GetRuin() ) continue; // is burning or exploding?
if ( pObj->GetDead() ) continue; // dead man? 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 && if ( oType == OBJECT_WAYPOINT &&
pObj->GetEnable() && !pObj->GetLock() &&
m_object->GetTrainer() ) // driving vehicle? m_object->GetTrainer() ) // driving vehicle?
{ {
Math::Vector oPos = pObj->GetPosition(); Math::Vector oPos = pObj->GetPosition();
@ -2724,8 +2721,6 @@ bool CPhysics::JostleObject(CObject* pObj, float force)
bool CPhysics::ExploOther(ObjectType iType, bool CPhysics::ExploOther(ObjectType iType,
CObject *pObj, ObjectType oType, float force) CObject *pObj, ObjectType oType, float force)
{ {
if ( !pObj->GetEnable() ) return true;
JostleObject(pObj, 1.0f); // shakes the object JostleObject(pObj, 1.0f); // shakes the object
if ( force > 50.0f && if ( force > 50.0f &&

View File

@ -153,9 +153,7 @@ bool CMainShort::CreateShortcuts()
positions[teamIndex].x += dim.x; positions[teamIndex].x += dim.x;
m_shortcuts.push_back(pObj); m_shortcuts.push_back(pObj);
std::string tooltipName; shortcut->SetTooltip(pObj->GetTooltipText());
pObj->GetTooltipName(tooltipName);
shortcut->SetTooltip(tooltipName);
rank ++; rank ++;

View File

@ -833,14 +833,12 @@ bool CObjectInterface::CreateInterface(bool bSelect)
pw = static_cast< CWindow* >(m_interface->SearchControl(EVENT_WINDOW0)); pw = static_cast< CWindow* >(m_interface->SearchControl(EVENT_WINDOW0));
if ( pw == 0 ) return false; if ( pw == 0 ) return false;
std::string tooltipLabel;
m_object->GetTooltipName(tooltipLabel);
pos.x = 0.0f; pos.x = 0.0f;
pos.y = 64.0f/480.0f; pos.y = 64.0f/480.0f;
ddim.x = 540.0f/640.0f; ddim.x = 540.0f/640.0f;
if ( !m_main->GetShowMap() ) ddim.x = 640.0f/640.0f; if ( !m_main->GetShowMap() ) ddim.x = 640.0f/640.0f;
ddim.y = 16.0f/480.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.x = 33.0f/640.0f;
dim.y = 33.0f/480.0f; dim.y = 33.0f/480.0f;