CRangedObject

master
krzys-h 2015-08-12 18:05:11 +02:00
parent 15bf98da40
commit 1b73830f28
7 changed files with 49 additions and 11 deletions

View File

@ -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<int>(ObjectInterfaceType::Ranged)] = true;
}
virtual ~CRangedObject()
{}
//! Return object operation radius
virtual float GetShowLimitRadius() = 0;
};

View File

@ -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)
};

View File

@ -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<int>(ObjectInterfaceType::Programmable)] = false;

View File

@ -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;

View File

@ -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()
{

View File

@ -130,9 +130,6 @@ public:
virtual bool GetRuin();
virtual bool GetActive();
// Not sure. CRangedObject?
virtual float GetShowLimitRadius();
virtual CPhysics* GetPhysics();
virtual CMotion* GetMotion();

View File

@ -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<CRangedObject*>(obj)->GetShowLimitRadius();
if (range == 0.0f) return;
SetShowLimit(0, Gfx::PARTILIMIT1, obj, obj->GetPosition(), range);
}
//! Advances the boundaries shown