From 1b73830f286b73b846d168db1ac0a12ba2ac6ee6 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Wed, 12 Aug 2015 18:05:11 +0200 Subject: [PATCH] CRangedObject --- src/object/interface/ranged_object.h | 40 ++++++++++++++++++++++++++++ src/object/object_interface_type.h | 1 + src/object/old_object.cpp | 1 + src/object/old_object.h | 4 ++- src/object/old_object_interface.cpp | 5 ---- src/object/old_object_interface.h | 3 --- src/object/robotmain.cpp | 6 +++-- 7 files changed, 49 insertions(+), 11 deletions(-) create mode 100644 src/object/interface/ranged_object.h diff --git a/src/object/interface/ranged_object.h b/src/object/interface/ranged_object.h new file mode 100644 index 00000000..c841056f --- /dev/null +++ b/src/object/interface/ranged_object.h @@ -0,0 +1,40 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsiteс.ch; http://colobot.info; http://github.com/colobot + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://gnu.org/licenses + */ + +#pragma once + +#include "object/object_interface_type.h" + +/** + * \class CRangedObject + * \brief Interface for objects that have a button in UI for showing range + */ +class CRangedObject +{ +public: + explicit CRangedObject(ObjectInterfaceTypes& types) + { + types[static_cast(ObjectInterfaceType::Ranged)] = true; + } + virtual ~CRangedObject() + {} + + //! Return object operation radius + virtual float GetShowLimitRadius() = 0; +}; diff --git a/src/object/object_interface_type.h b/src/object/object_interface_type.h index afe8214c..7616af28 100644 --- a/src/object/object_interface_type.h +++ b/src/object/object_interface_type.h @@ -43,6 +43,7 @@ enum class ObjectInterfaceType Movable, //!< objects that can move Controllable, //!< objects that can be selected and controlled by the player PowerContainer, //!< objects that hold power + Ranged, //!< objects that have a operation range to be displayed after pressing button in the UI Old, //!< old objects, TODO: remove once no longer necessary Max //!< maximum value (for getting number of items in enum) }; diff --git a/src/object/old_object.cpp b/src/object/old_object.cpp index 24c437c2..5a181480 100644 --- a/src/object/old_object.cpp +++ b/src/object/old_object.cpp @@ -85,6 +85,7 @@ COldObject::COldObject(int id) , CMovableObject(m_implementedInterfaces) , CControllableObject(m_implementedInterfaces) , CPowerContainerObjectImpl(m_implementedInterfaces, this) + , CRangedObject(m_implementedInterfaces) { // A bit of a hack since we don't have subclasses yet, set externally in SetProgrammable() m_implementedInterfaces[static_cast(ObjectInterfaceType::Programmable)] = false; diff --git a/src/object/old_object.h b/src/object/old_object.h index ed1c979e..87296647 100644 --- a/src/object/old_object.h +++ b/src/object/old_object.h @@ -34,6 +34,7 @@ #include "object/interface/power_container_object.h" #include "object/interface/powered_object.h" #include "object/interface/programmable_object.h" +#include "object/interface/ranged_object.h" #include "object/interface/task_executor_object.h" #include "object/interface/transportable_object.h" @@ -78,7 +79,8 @@ class COldObject : public CObject, public CPoweredObject, public CMovableObject, public CControllableObject, - public CPowerContainerObjectImpl + public CPowerContainerObjectImpl, + public CRangedObject { friend class CObjectFactory; friend class CObjectManager; diff --git a/src/object/old_object_interface.cpp b/src/object/old_object_interface.cpp index 5aff4cd0..5d53ceb8 100644 --- a/src/object/old_object_interface.cpp +++ b/src/object/old_object_interface.cpp @@ -220,11 +220,6 @@ bool COldObjectInterface::GetActive() //throw std::logic_error("GetActive: not implemented!"); } -float COldObjectInterface::GetShowLimitRadius() -{ - throw std::logic_error("GetShowLimitRadius: not implemented!"); -} - CPhysics* COldObjectInterface::GetPhysics() { diff --git a/src/object/old_object_interface.h b/src/object/old_object_interface.h index c70bc9f3..57e0126a 100644 --- a/src/object/old_object_interface.h +++ b/src/object/old_object_interface.h @@ -130,9 +130,6 @@ public: virtual bool GetRuin(); virtual bool GetActive(); - // Not sure. CRangedObject? - virtual float GetShowLimitRadius(); - virtual CPhysics* GetPhysics(); virtual CMotion* GetMotion(); diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index d6a521e8..a8e32be0 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -4619,8 +4619,10 @@ void CRobotMain::StartShowLimit() { CObject* obj = GetSelect(); if (obj == nullptr) return; - if (obj->GetShowLimitRadius() == 0.0f) return; - SetShowLimit(0, Gfx::PARTILIMIT1, obj, obj->GetPosition(), obj->GetShowLimitRadius()); + if (!obj->Implements(ObjectInterfaceType::Ranged)) return; + float range = dynamic_cast(obj)->GetShowLimitRadius(); + if (range == 0.0f) return; + SetShowLimit(0, Gfx::PARTILIMIT1, obj, obj->GetPosition(), range); } //! Advances the boundaries shown