Moved GetPhysics() and GetMotion() to CMovableObject; moved trace drawing to CTraceDrawingObject

master
krzys-h 2015-08-13 10:49:26 +02:00
parent 93a06c0c23
commit e937db94c8
36 changed files with 370 additions and 310 deletions

View File

@ -150,6 +150,7 @@ set(BASE_SOURCES
object/auto/autopowerstation.cpp
object/auto/autotower.cpp
object/drive_type.cpp
object/interface/trace_drawing_object.cpp
object/implementation/power_container_impl.cpp
object/implementation/programmable_impl.cpp
object/implementation/task_executor_impl.cpp
@ -199,7 +200,6 @@ set(BASE_SOURCES
object/task/taskturn.cpp
object/task/taskwait.cpp
object/tool_type.cpp
object/trace_color.cpp
object/subclass/exchange_post.cpp
object/subclass/static_object.cpp
physics/physics.cpp

View File

@ -35,6 +35,7 @@
#include "object/robotmain.h"
#include "object/interface/carrier_object.h"
#include "object/interface/movable_object.h"
#include "object/interface/powered_object.h"
#include "object/interface/transportable_object.h"
@ -1468,8 +1469,10 @@ bool CCamera::EventFrameBack(const Event &event)
m_eyePt = RotateView(lookatPt, h, v, d);
CPhysics* physics = m_cameraObj->GetPhysics();
if ( (physics != NULL) && physics->GetLand() ) // ground?
bool ground = true;
if (m_cameraObj->Implements(ObjectInterfaceType::Movable))
ground = dynamic_cast<CMovableObject*>(m_cameraObj)->GetPhysics()->GetLand();
if ( ground ) // ground?
{
Math::Vector pos = lookatPt + (lookatPt - m_eyePt);
float floor = m_terrain->GetHeightToFloor(pos) - 4.0f;

View File

@ -269,9 +269,11 @@ bool CPyro::Create(PyroType type, CObject* obj, float force)
{
m_object->SetDead(true);
CMotion* motion = m_object->GetMotion();
if (motion != nullptr)
if ( obj->Implements(ObjectInterfaceType::Movable) )
{
CMotion* motion = dynamic_cast<CMovableObject*>(obj)->GetMotion();
motion->SetAction(MHS_DEADg, 1.0f);
}
m_camera->StartCentering(m_object, Math::PI*0.5f, 99.9f, 0.0f, 1.5f);
m_camera->StartOver(CAM_OVER_EFFECT_FADEOUT_WHITE, m_pos, 1.0f);
@ -282,9 +284,9 @@ bool CPyro::Create(PyroType type, CObject* obj, float force)
{
m_object->SetDead(true);
CMotion* motion = m_object->GetMotion();
if ( motion != nullptr )
if ( obj->Implements(ObjectInterfaceType::Movable) )
{
CMotion* motion = dynamic_cast<CMovableObject*>(obj)->GetMotion();
motion->SetAction(MHS_DEADw, 4.0f);
}
m_camera->StartCentering(m_object, Math::PI*0.5f, 99.9f, 0.0f, 3.0f);

View File

@ -1246,9 +1246,9 @@ void CAutoBase::FreezeCargo(bool freeze)
if ( dist < 32.0f )
{
m_cargoObjects.insert(obj);
CPhysics* physics = obj->GetPhysics();
if ( physics != nullptr )
if ( obj->Implements(ObjectInterfaceType::Movable) )
{
CPhysics* physics = dynamic_cast<CMovableObject*>(obj)->GetPhysics();
physics->SetFreeze(freeze);
}
}

View File

@ -385,13 +385,11 @@ bool CAutoFactory::EventProcess(const Event &event)
}
vehicle = SearchVehicle();
if ( vehicle != 0 )
if ( vehicle != nullptr )
{
physics = vehicle->GetPhysics();
if ( physics != 0 )
{
physics->SetFreeze(false); // can move
}
assert(vehicle->Implements(ObjectInterfaceType::Movable));
physics = dynamic_cast<CMovableObject*>(vehicle)->GetPhysics();
physics->SetFreeze(false); // can move
vehicle->SetLock(false); // vehicle useable
vehicle->SetRotationY(m_object->GetRotationY()+Math::PI);
@ -656,11 +654,9 @@ bool CAutoFactory::CreateVehicle()
vehicle->SetLock(true); // not usable
CPhysics* physics = vehicle->GetPhysics();
if ( physics != nullptr )
{
physics->SetFreeze(true); // it doesn't move
}
assert(vehicle->Implements(ObjectInterfaceType::Movable));
CPhysics* physics = dynamic_cast<CMovableObject*>(vehicle)->GetPhysics();
physics->SetFreeze(true); // it doesn't move
if (vehicle->Implements(ObjectInterfaceType::Programmable))
{

View File

@ -268,8 +268,7 @@ CObject* CAutoRepair::SearchVehicle()
type != OBJECT_MOBILEit &&
type != OBJECT_MOBILEdr ) continue;
CPhysics* physics = obj->GetPhysics();
if ( physics != nullptr && !physics->GetLand() ) continue; // in flight?
if ( obj->Implements(ObjectInterfaceType::Movable) && !dynamic_cast<CMovableObject*>(obj)->GetPhysics()->GetLand() ) continue; // in flight?
Math::Vector oPos = obj->GetPosition();
float dist = Math::Distance(oPos, sPos);
@ -323,4 +322,3 @@ bool CAutoRepair::Read(CLevelParserLine* line)
return true;
}

View File

@ -279,9 +279,9 @@ CObject* CAutoTower::SearchTarget(Math::Vector &impact)
//? if ( g_researchDone & RESEARCH_QUICK )
if ( false )
{
CPhysics* physics = obj->GetPhysics();
if ( physics != nullptr )
if ( obj->Implements(ObjectInterfaceType::Movable) )
{
CPhysics* physics = dynamic_cast<CMovableObject*>(obj)->GetPhysics();
float speed = fabs(physics->GetLinMotionX(MO_REASPEED));
if ( speed > 20.0f ) continue; // moving too fast?
}

View File

@ -410,9 +410,8 @@ void CProgrammableObjectImpl::TraceRecordStart()
TraceRecordStop();
}
assert(m_object->Implements(ObjectInterfaceType::Old)); // TODO
CMotionVehicle* motionVehicle = dynamic_cast<CMotionVehicle*>(dynamic_cast<COldObjectInterface*>(m_object)->GetMotion());
assert(motionVehicle != nullptr);
assert(m_object->Implements(ObjectInterfaceType::TraceDrawing));
CTraceDrawingObject* traceDrawing = dynamic_cast<CTraceDrawingObject*>(m_object);
m_traceRecord = true;
@ -421,9 +420,9 @@ void CProgrammableObjectImpl::TraceRecordStart()
m_tracePos = m_object->GetPosition();
m_traceAngle = m_object->GetRotationY();
if ( motionVehicle->GetTraceDown() ) // pencil down?
if ( traceDrawing->GetTraceDown() ) // pencil down?
{
m_traceColor = motionVehicle->GetTraceColor();
m_traceColor = traceDrawing->GetTraceColor();
}
else // pen up?
{
@ -442,11 +441,10 @@ void CProgrammableObjectImpl::TraceRecordFrame()
Math::Vector pos;
float angle, len, speed;
assert(m_object->Implements(ObjectInterfaceType::Old)); // TODO
CMotionVehicle* motionVehicle = dynamic_cast<CMotionVehicle*>(dynamic_cast<COldObjectInterface*>(m_object)->GetMotion());
assert(motionVehicle != nullptr);
assert(m_object->Implements(ObjectInterfaceType::TraceDrawing));
CTraceDrawingObject* traceDrawing = dynamic_cast<CTraceDrawingObject*>(m_object);
CPhysics* physics = dynamic_cast<COldObjectInterface*>(m_object)->GetPhysics();
CPhysics* physics = dynamic_cast<CMovableObject*>(m_object)->GetPhysics();
speed = physics->GetLinMotionX(MO_REASPEED);
if ( speed > 0.0f ) oper = TO_ADVANCE;
@ -456,9 +454,9 @@ void CProgrammableObjectImpl::TraceRecordFrame()
if ( speed != 0.0f ) oper = TO_TURN;
TraceColor color = TraceColor::Default;
if ( motionVehicle->GetTraceDown() ) // pencil down?
if ( traceDrawing->GetTraceDown() ) // pencil down?
{
color = motionVehicle->GetTraceColor();
color = traceDrawing->GetTraceColor();
}
if ( oper != m_traceOper ||

View File

@ -21,8 +21,7 @@
#include "object/interface/interactive_object.h"
#include "object/interface/programmable_object.h"
#include "object/trace_color.h"
#include "object/interface/trace_drawing_object.h"
#include "math/vector.h"

View File

@ -27,7 +27,7 @@
* \class CFlyingObject
* \brief Interface for objects that can fly
*/
class CFlyingObject : CMovableObject
class CFlyingObject : public CMovableObject
{
public:
explicit CFlyingObject(ObjectInterfaceTypes& types)

View File

@ -27,7 +27,7 @@
* \class CJetFlyingObject
* \brief Interface for objects that can fly using a jet engine
*/
class CJetFlyingObject : CFlyingObject
class CJetFlyingObject : public CFlyingObject
{
public:
explicit CJetFlyingObject(ObjectInterfaceTypes& types)
@ -38,8 +38,15 @@ public:
virtual ~CJetFlyingObject()
{}
// TODO: Refactor naming of these functions
//! Sets jet engine heating speed (bigger = slower, 0 for infinite)
virtual void SetRange(float range) = 0;
//! Returns jet engine heating speed (bigger = slower, 0 for infinite)
virtual float GetRange() = 0;
//! Sets current jet engine heat level (this is actually how much is left before it overheats, so smaller = more hot)
virtual void SetReactorRange(float reactorRange) = 0;
//! Returns current jet engine heat level (this is actually how much is left before it overheats, so smaller = more hot)
virtual float GetReactorRange() = 0;
};

View File

@ -24,6 +24,10 @@
/**
* \class CMovableObject
* \brief Interface for objects that can move (have an engine)
*
* TODO: Currently, it just returns pointers to CPhysics and CMotion.
* These classes should be probably merged with CObject,
* and maybe even split into some more interfaces.
*/
class CMovableObject
{
@ -34,4 +38,9 @@ public:
}
virtual ~CMovableObject()
{}
//! Returns CPhysics instance associated with this object. If the object implements Movable interface, and type != OBJECT_TOTO, this can be assumed to be != nullptr
virtual CPhysics* GetPhysics() = 0;
//! Returns CMotion instance associated with this object. If the object implements Movable interface, this can be assumed to be != nullptr
virtual CMotion* GetMotion() = 0;
};

View File

@ -21,7 +21,8 @@
#include "object/object.h"
#include "object/object_interface_type.h"
#include "object/trace_color.h"
#include "object/interface/trace_drawing_object.h"
#include "object/task/taskflag.h"
#include "object/task/taskgoto.h"

View File

@ -16,7 +16,8 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://gnu.org/licenses
*/
#include "object/trace_color.h"
#include "object/interface/trace_drawing_object.h"
std::string TraceColorName(TraceColor color)
{

View File

@ -16,11 +16,12 @@
* 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 <string>
#include "object/object_interface_type.h"
enum class TraceColor : int
enum class TraceColor
{
Default = -1,
@ -44,5 +45,26 @@ enum class TraceColor : int
RedArrow = 17,
Max,
};
std::string TraceColorName(TraceColor c);
/**
* \class CTraceDrawingObject
* \brief Interface for objects that can draw wheel trace (at the moment, all movable objects)
*/
class CTraceDrawingObject
{
public:
explicit CTraceDrawingObject(ObjectInterfaceTypes& types)
{
types[static_cast<int>(ObjectInterfaceType::TraceDrawing)] = true;
}
virtual ~CTraceDrawingObject()
{}
virtual bool GetTraceDown() = 0;
virtual void SetTraceDown(bool down) = 0;
virtual TraceColor GetTraceColor() = 0;
virtual void SetTraceColor(TraceColor color) = 0;
virtual float GetTraceWidth() = 0;
virtual void SetTraceWidth(float width) = 0;
};

View File

@ -27,6 +27,8 @@
#include "object/object.h"
#include "object/robotmain.h"
#include "object/interface/movable_object.h"
#include "object/motion/motionhuman.h"
@ -67,7 +69,6 @@ bool CMainMovie::Start(MainMovieType type, float time)
Math::Matrix* mat;
Math::Vector pos;
CObject* pObj;
CMotion* motion;
m_type = type;
m_speed = 1.0f/time;
@ -76,17 +77,14 @@ bool CMainMovie::Start(MainMovieType type, float time)
if ( m_type == MM_SATCOMopen )
{
pObj = m_main->SearchHuman();
if ( pObj == 0 )
if ( pObj == nullptr )
{
m_type = MM_NONE; // it's over!
return true;
}
motion = pObj->GetMotion();
if ( motion != 0 )
{
motion->SetAction(MHS_SATCOM, 0.5f); // reads the SatCom
}
assert(pObj->Implements(ObjectInterfaceType::Movable));
dynamic_cast<CMovableObject*>(pObj)->GetMotion()->SetAction(MHS_SATCOM, 0.5f); // reads the SatCom
m_camera->GetCamera(m_initialEye, m_initialLookat);
m_camera->SetType(Gfx::CAM_TYPE_SCRIPT);
@ -105,13 +103,10 @@ bool CMainMovie::Start(MainMovieType type, float time)
if ( m_type == MM_SATCOMclose )
{
pObj = m_main->SearchHuman();
if ( pObj != 0 )
if ( pObj != nullptr )
{
motion = pObj->GetMotion();
if ( motion != 0 )
{
motion->SetAction(-1); // finishes reading SatCom
}
assert(pObj->Implements(ObjectInterfaceType::Movable));
dynamic_cast<CMovableObject*>(pObj)->GetMotion()->SetAction(-1); // finishes reading SatCom
}
m_camera->SetType(Gfx::CAM_TYPE_BACK);
@ -126,18 +121,14 @@ bool CMainMovie::Start(MainMovieType type, float time)
bool CMainMovie::Stop()
{
CObject* pObj;
CMotion* motion;
if ( m_type == MM_SATCOMopen )
{
pObj = m_main->SearchHuman();
if ( pObj != 0 )
if ( pObj != nullptr )
{
motion = pObj->GetMotion();
if ( motion != 0 )
{
motion->SetAction(-1); // finishes reading SatCom
}
assert(pObj->Implements(ObjectInterfaceType::Movable));
dynamic_cast<CMovableObject*>(pObj)->GetMotion()->SetAction(-1); // finishes reading SatCom
}
}
@ -232,4 +223,3 @@ MainMovieType CMainMovie::GetStopType()
{
return m_stopType;
}

View File

@ -68,10 +68,6 @@ CMotionVehicle::CMotionVehicle(COldObject* object) : CMotion(object)
m_wheelLastAngle = Math::Vector(0.0f, 0.0f, 0.0f);
m_posKey = Math::Vector(0.0f, 0.0f, 0.0f);
m_bFlyFix = false;
m_bTraceDown = false;
m_traceColor = TraceColor::Black; // black
m_traceWidth = 0.5f;
}
// Object's destructor.
@ -1860,37 +1856,3 @@ void CMotionVehicle::UpdateTrackMapping(float left, float right, ObjectType type
}
}
// State management of the pencil drawing robot.
bool CMotionVehicle::GetTraceDown()
{
return m_bTraceDown;
}
void CMotionVehicle::SetTraceDown(bool bDown)
{
m_bTraceDown = bDown;
}
TraceColor CMotionVehicle::GetTraceColor()
{
return m_traceColor;
}
void CMotionVehicle::SetTraceColor(TraceColor color)
{
m_traceColor = color;
}
float CMotionVehicle::GetTraceWidth()
{
return m_traceWidth;
}
void CMotionVehicle::SetTraceWidth(float width)
{
m_traceWidth = width;
}

View File

@ -22,9 +22,6 @@
#include "object/motion/motion.h"
#include "object/trace_color.h"
class CMotionVehicle : public CMotion
{
@ -36,13 +33,6 @@ public:
void Create(Math::Vector pos, float angle, ObjectType type, float power, Gfx::COldModelManager* modelManager);
bool EventProcess(const Event &event);
bool GetTraceDown();
void SetTraceDown(bool bDown);
TraceColor GetTraceColor();
void SetTraceColor(TraceColor color);
float GetTraceWidth();
void SetTraceWidth(float width);
protected:
void CreatePhysics(ObjectType type);
bool EventFrame(const Event &event);
@ -64,7 +54,4 @@ protected:
Math::Vector m_wheelLastAngle;
Math::Vector m_posKey;
bool m_bFlyFix;
bool m_bTraceDown;
TraceColor m_traceColor;
float m_traceWidth;
};

View File

@ -2553,7 +2553,7 @@ CObjectUPtr CObjectFactory::CreateVehicle(const ObjectCreateParams& params)
{
auto motion = MakeUnique<CMotionToto>(obj.get());
motion->Create(pos, angle, type, 1.0f, m_oldModelManager);
obj->SetMotion(std::move(motion));
obj->SetMovable(std::move(motion), nullptr);
return std::move(obj);
}
@ -2591,9 +2591,8 @@ CObjectUPtr CObjectFactory::CreateVehicle(const ObjectCreateParams& params)
motion->Create(pos, angle, type, power, m_oldModelManager);
obj->SetProgrammable(true);
obj->SetMotion(std::move(motion));
obj->SetPhysics(std::move(physics));
obj->SetProgrammable();
obj->SetMovable(std::move(motion), std::move(physics));
return std::move(obj);
}
@ -2641,9 +2640,8 @@ CObjectUPtr CObjectFactory::CreateInsect(const ObjectCreateParams& params)
motion->Create(pos, angle, type, 0.0f, m_oldModelManager);
obj->SetMotion(std::move(motion));
obj->SetPhysics(std::move(physics));
obj->SetProgrammable(true);
obj->SetProgrammable();
obj->SetMovable(std::move(motion), std::move(physics));
return std::move(obj);
}

View File

@ -46,6 +46,7 @@ enum class ObjectInterfaceType
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
TraceDrawing, //!< objects that can draw wheel trace
Old, //!< old objects, TODO: remove once no longer necessary
Max //!< maximum value (for getting number of items in enum)
};

View File

@ -254,7 +254,6 @@ CObject* CObjectManager::Radar(CObject* pThis, Math::Vector thisPosition, float
CObject* CObjectManager::Radar(CObject* pThis, Math::Vector thisPosition, float thisAngle, std::vector<ObjectType> type, float angle, float focus, float minDist, float maxDist, bool furthest, RadarFilter filter, bool cbotTypes)
{
CObject *pObj, *pBest;
CPhysics* physics;
Math::Vector iPos, oPos;
float best, iAngle, d, a;
ObjectType oType;
@ -319,13 +318,21 @@ CObject* CObjectManager::Radar(CObject* pThis, Math::Vector thisPosition, float
if ( filter_flying == FILTER_ONLYLANDING )
{
physics = pObj->GetPhysics();
if ( physics != nullptr && !physics->GetLand() ) continue;
if ( pObj->Implements(ObjectInterfaceType::Movable) )
{
CPhysics* physics = dynamic_cast<CMovableObject*>(pObj)->GetPhysics();
if ( physics != nullptr )
{
if ( !physics->GetLand() ) continue;
}
}
}
if ( filter_flying == FILTER_ONLYFLYING )
{
physics = pObj->GetPhysics();
if ( physics != nullptr && physics->GetLand() ) continue;
if ( !pObj->Implements(ObjectInterfaceType::Movable) ) continue;
CPhysics* physics = dynamic_cast<CMovableObject*>(pObj)->GetPhysics();
if ( physics == nullptr ) continue;
if ( physics->GetLand() ) continue;
}
if ( filter_team != 0 && pObj->GetTeam() != filter_team )

View File

@ -86,9 +86,12 @@ COldObject::COldObject(int id)
, CControllableObject(m_implementedInterfaces)
, CPowerContainerObjectImpl(m_implementedInterfaces, this)
, CRangedObject(m_implementedInterfaces)
, CTraceDrawingObject(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;
// Another hack, see SetMovable()
m_implementedInterfaces[static_cast<int>(ObjectInterfaceType::Movable)] = false;
// Another hack
m_implementedInterfaces[static_cast<int>(ObjectInterfaceType::Jostleable)] = false;
@ -171,6 +174,12 @@ COldObject::COldObject(int id)
m_buttonAxe = EVENT_NULL;
m_reactorRange = 1.0f;
m_traceDown = false;
m_traceColor = TraceColor::Black;
m_traceWidth = 0.5f;
DeleteAllCrashSpheres();
}
@ -2235,6 +2244,18 @@ float COldObject::GetRange()
return m_range;
}
void COldObject::SetReactorRange(float reactorRange)
{
if (reactorRange > 1.0f) reactorRange = 1.0f;
if (reactorRange < 0.0f) reactorRange = 0.0f;
m_reactorRange = reactorRange;
}
float COldObject::GetReactorRange()
{
return m_reactorRange;
}
// Management of transparency of the object.
@ -2858,17 +2879,6 @@ CPhysics* COldObject::GetPhysics()
return m_physics.get();
}
void COldObject::SetPhysics(std::unique_ptr<CPhysics> physics)
{
m_physics = std::move(physics);
}
// TODO: Temporary hack until we'll have subclasses for objects
void COldObject::SetProgrammable(bool programmable)
{
m_implementedInterfaces[static_cast<int>(ObjectInterfaceType::Programmable)] = programmable;
}
// Returns the movement associated to the object.
CMotion* COldObject::GetMotion()
@ -2876,9 +2886,18 @@ CMotion* COldObject::GetMotion()
return m_motion.get();
}
void COldObject::SetMotion(std::unique_ptr<CMotion> motion)
// TODO: Temporary hack until we'll have subclasses for objects
void COldObject::SetProgrammable()
{
m_implementedInterfaces[static_cast<int>(ObjectInterfaceType::Programmable)] = true;
}
// TODO: Another hack
void COldObject::SetMovable(std::unique_ptr<CMotion> motion, std::unique_ptr<CPhysics> physics)
{
m_motion = std::move(motion);
m_physics = std::move(physics);
m_implementedInterfaces[static_cast<int>(ObjectInterfaceType::Movable)] = true;
}
// Returns the controller associated to the object.
@ -3028,10 +3047,10 @@ Error COldObject::StartTaskPen(bool down, TraceColor color)
assert(motionVehicle != nullptr);
if (color == TraceColor::Default)
color = motionVehicle->GetTraceColor();
color = GetTraceColor();
motionVehicle->SetTraceDown(down);
motionVehicle->SetTraceColor(color);
SetTraceDown(down);
SetTraceColor(color);
m_physics->SetMotorSpeedX(0.0f);
m_physics->SetMotorSpeedY(0.0f);
@ -3190,3 +3209,35 @@ void COldObject::StopProgram()
m_motion->SetAction(-1);
}
// State management of the pencil drawing robot.
bool COldObject::GetTraceDown()
{
return m_traceDown;
}
void COldObject::SetTraceDown(bool down)
{
m_traceDown = down;
}
TraceColor COldObject::GetTraceColor()
{
return m_traceColor;
}
void COldObject::SetTraceColor(TraceColor color)
{
m_traceColor = color;
}
float COldObject::GetTraceWidth()
{
return m_traceWidth;
}
void COldObject::SetTraceWidth(float width)
{
m_traceWidth = width;
}

View File

@ -38,6 +38,7 @@
#include "object/interface/programmable_object.h"
#include "object/interface/ranged_object.h"
#include "object/interface/task_executor_object.h"
#include "object/interface/trace_drawing_object.h"
#include "object/interface/transportable_object.h"
#include "object/implementation/power_container_impl.h"
@ -82,16 +83,16 @@ class COldObject : public CObject,
public CJetFlyingObject,
public CControllableObject,
public CPowerContainerObjectImpl,
public CRangedObject
public CRangedObject,
public CTraceDrawingObject
{
friend class CObjectFactory;
friend class CObjectManager;
protected:
void DeleteObject(bool bAll=false);
void SetPhysics(std::unique_ptr<CPhysics> physics);
void SetProgrammable(bool programmable);
void SetMotion(std::unique_ptr<CMotion> motion);
void SetProgrammable();
void SetMovable(std::unique_ptr<CMotion> motion, std::unique_ptr<CPhysics> physics);
void SetAuto(std::unique_ptr<CAuto> automat);
void SetOption(int option);
void SetJostlingSphere(const Math::Sphere& sphere);
@ -198,6 +199,9 @@ public:
void SetRange(float delay) override;
float GetRange() override;
void SetReactorRange(float reactorRange) override;
float GetReactorRange() override;
void SetTransparency(float value) override;
void SetFixed(bool bFixed) override;
@ -305,6 +309,13 @@ public:
void StopProgram() override;
bool GetTraceDown() override;
void SetTraceDown(bool down) override;
TraceColor GetTraceColor() override;
void SetTraceColor(TraceColor color) override;
float GetTraceWidth() override;
void SetTraceWidth(float width) override;
protected:
bool EventFrame(const Event &event);
void VirusFrame(float rTime);
@ -394,4 +405,10 @@ protected:
float m_time;
float m_burnTime;
float m_reactorRange;
bool m_traceDown;
TraceColor m_traceColor;
float m_traceWidth;
};

View File

@ -211,16 +211,6 @@ bool COldObjectInterface::GetActive()
}
CPhysics* COldObjectInterface::GetPhysics()
{
throw std::logic_error("GetPhysics: not implemented!");
}
CMotion* COldObjectInterface::GetMotion()
{
throw std::logic_error("GetMotion: not implemented!");
}
CAuto* COldObjectInterface::GetAuto()
{
throw std::logic_error("GetAuto: not implemented!");

View File

@ -126,9 +126,6 @@ public:
virtual bool GetRuin();
virtual bool GetActive();
virtual CPhysics* GetPhysics();
virtual CMotion* GetMotion();
// This will be eventually removed after refactoring to subclasses
virtual CAuto* GetAuto();

View File

@ -1241,9 +1241,8 @@ void CRobotMain::ExecuteCmd(char *cmd)
object->SetShield(1.0f);
CPhysics* physics = object->GetPhysics();
if (physics != nullptr)
physics->SetReactorRange(1.0f);
if (object->Implements(ObjectInterfaceType::JetFlying))
dynamic_cast<CJetFlyingObject*>(object)->SetReactorRange(1.0f);
}
return;
}
@ -1277,9 +1276,8 @@ void CRobotMain::ExecuteCmd(char *cmd)
CObject* object = GetSelect();
if (object != nullptr)
{
CPhysics* physics = object->GetPhysics();
if (physics != nullptr)
physics->SetReactorRange(1.0f);
if (object->Implements(ObjectInterfaceType::JetFlying))
dynamic_cast<CJetFlyingObject*>(object)->SetReactorRange(1.0f);
}
return;
}
@ -1416,8 +1414,8 @@ void CRobotMain::StartDisplayInfo(int index, bool movie)
if (!m_editLock && movie && !m_movie->IsExist() && human)
{
CMotion* motion = obj->GetMotion();
if (motion != nullptr && motion->GetAction() == -1)
assert(obj->Implements(ObjectInterfaceType::Movable));
if (dynamic_cast<CMovableObject*>(obj)->GetMotion()->GetAction() == -1)
{
m_movieInfoIndex = index;
m_movie->Start(MM_SATCOMopen, 2.5f);
@ -1784,9 +1782,9 @@ void CRobotMain::SelectOneObject(CObject* obj, bool displayError)
CObject* toto = SearchToto();
if (toto != nullptr)
{
CMotionToto* mt = static_cast<CMotionToto*>(toto->GetMotion());
if (mt != nullptr)
mt->SetLinkType(type);
assert(toto->Implements(ObjectInterfaceType::Movable));
CMotionToto* mt = static_cast<CMotionToto*>(dynamic_cast<CMovableObject*>(toto)->GetMotion());
mt->SetLinkType(type);
}
}
@ -2848,9 +2846,9 @@ void CRobotMain::ScenePerso()
{
obj->SetDrawFront(true); // draws the interface
CMotionHuman* mh = static_cast<CMotionHuman*>(obj->GetMotion());
if (mh != nullptr)
mh->StartDisplayPerso();
assert(obj->Implements(ObjectInterfaceType::Movable));
CMotionHuman* mh = static_cast<CMotionHuman*>(dynamic_cast<CMovableObject*>(obj)->GetMotion());
mh->StartDisplayPerso();
}
}
@ -3572,7 +3570,8 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
if (m_fixScene && type == OBJECT_HUMAN)
{
CMotion* motion = obj->GetMotion();
assert(obj->Implements(ObjectInterfaceType::Movable));
CMotion* motion = dynamic_cast<CMovableObject*>(obj)->GetMotion();
if (m_phase == PHASE_WIN ) motion->SetAction(MHS_WIN, 0.4f);
if (m_phase == PHASE_LOST) motion->SetAction(MHS_LOST, 0.5f);
}

View File

@ -767,7 +767,7 @@ Error CTaskGoto::IsEnded()
if ( m_phase == TGP_BEAMWCOLD ) // expects cool reactor?
{
if ( m_altitude != 0.0f &&
m_physics->GetReactorRange() < 1.0f ) return ERR_CONTINUE;
(m_object->Implements(ObjectInterfaceType::JetFlying) && dynamic_cast<CJetFlyingObject*>(m_object)->GetReactorRange() < 1.0f) ) return ERR_CONTINUE;
m_phase = TGP_BEAMUP;
}
@ -789,7 +789,7 @@ Error CTaskGoto::IsEnded()
if ( m_phase == TGP_BEAMGOTO ) // goto dot list ?
{
if ( m_altitude != 0.0f &&
m_physics->GetReactorRange() < 0.1f ) // overheating?
(m_object->Implements(ObjectInterfaceType::JetFlying) && dynamic_cast<CJetFlyingObject*>(m_object)->GetReactorRange() < 0.1f) ) // overheating?
{
m_physics->SetMotorSpeedX(0.0f); // stops the advance
m_physics->SetMotorSpeedZ(0.0f); // stops the rotation

View File

@ -21,7 +21,7 @@
#pragma once
#include "object/trace_color.h"
#include "object/interface/trace_drawing_object.h"
#include "object/task/task.h"
#include "object/task/taskflag.h"

View File

@ -24,9 +24,9 @@
#include "object/task/task.h"
#include "math/vector.h"
#include "object/interface/trace_drawing_object.h"
#include "object/trace_color.h"
#include "math/vector.h"
enum TaskPenPhase

View File

@ -370,8 +370,8 @@ bool CTaskTerraform::Terraform()
}
else
{
motion = pObj->GetMotion();
if ( motion == 0 ) continue;
if ( !pObj->Implements(ObjectInterfaceType::Movable) == 0 ) continue;
motion = dynamic_cast<CMovableObject*>(pObj)->GetMotion();
dist = Math::Distance(m_terraPos, pObj->GetPosition());
if ( dist > ACTION_RADIUS ) continue;

View File

@ -99,7 +99,6 @@ CPhysics::CPhysics(COldObject* object)
m_bWheelParticleBrake = false;
m_absorbWater = 0.0f;
m_reactorTemperature = 0.0f;
m_reactorRange = 1.0f;
m_timeReactorFail = 0.0f;
m_lastEnergy = 0.0f;
m_lastSoundWater = 0.0f;
@ -164,7 +163,7 @@ bool CPhysics::Write(CLevelParserLine* line)
{
if ( m_object->Implements(ObjectInterfaceType::JetFlying) )
{
line->AddParam("reactorRange", MakeUnique<CLevelParserParam>(GetReactorRange()));
line->AddParam("reactorRange", MakeUnique<CLevelParserParam>(m_object->GetReactorRange()));
}
line->AddParam("land", MakeUnique<CLevelParserParam>(GetLand()));
}
@ -182,7 +181,7 @@ bool CPhysics::Read(CLevelParserLine* line)
{
if ( m_object->Implements(ObjectInterfaceType::JetFlying) )
{
SetReactorRange(line->GetParam("reactorRange")->AsFloat());
m_object->SetReactorRange(line->GetParam("reactorRange")->AsFloat());
}
SetLand(line->GetParam("land")->AsBool());
}
@ -292,19 +291,6 @@ bool CPhysics::GetFreeze()
}
// Returns the range of the reactor.
void CPhysics::SetReactorRange(float range)
{
m_reactorRange = range;
}
float CPhysics::GetReactorRange()
{
return m_reactorRange;
}
// Specifies the engine speed.
// x = forward/backward
// y = up/down
@ -862,15 +848,15 @@ void CPhysics::MotorUpdate(float aTime, float rTime)
if ( m_object->Implements(ObjectInterfaceType::JetFlying) &&
dynamic_cast<CJetFlyingObject*>(m_object)->GetRange() > 0.0f ) // limited flight range?
{
CJetFlyingObject* jetFlying = dynamic_cast<CJetFlyingObject*>(m_object);
if ( m_bLand || m_bSwim || m_bObstacle ) // on the ground or in the water?
{
factor = 1.0f;
if ( m_bObstacle ) factor = 3.0f; // in order to leave!
if ( m_bSwim ) factor = 3.0f; // cools faster in water
m_reactorRange += rTime*(1.0f/5.0f)*factor;
if ( m_reactorRange > 1.0f )
jetFlying->SetReactorRange(jetFlying->GetReactorRange() + rTime*(1.0f/5.0f)*factor);
if ( jetFlying->GetReactorRange() == 1.0f )
{
m_reactorRange = 1.0f;
if ( m_bLowLevel && m_object->GetSelect() ) // beep cool?
{
m_sound->Play(SOUND_INFO, m_object->GetPosition(), 1.0f, 2.0f);
@ -881,12 +867,11 @@ void CPhysics::MotorUpdate(float aTime, float rTime)
}
else // in flight?
{
m_reactorRange -= rTime*(1.0f/dynamic_cast<CJetFlyingObject*>(m_object)->GetRange());
if ( m_reactorRange < 0.0f ) m_reactorRange = 0.0f;
if ( m_reactorRange < 0.5f ) m_bLowLevel = true;
jetFlying->SetReactorRange(jetFlying->GetReactorRange() - rTime*(1.0f/jetFlying->GetRange()));
if ( jetFlying->GetReactorRange() < 0.5f ) m_bLowLevel = true;
}
if ( m_reactorRange == 0.0f ) // reactor tilt?
if ( jetFlying->GetReactorRange() == 0.0f ) // reactor tilt?
{
motorSpeed.y = -1.0f; // grave
SetFalling();
@ -966,7 +951,12 @@ void CPhysics::MotorUpdate(float aTime, float rTime)
pos = m_object->GetPosition();
h = m_terrain->GetFlyingLimit(pos, type==OBJECT_BEE);
h += m_object->GetCharacter()->height;
if ( motorSpeed.y > 0.0f && m_reactorRange > 0.1f && pos.y < h )
bool reactorCool = true;
if ( m_object->Implements(ObjectInterfaceType::JetFlying) )
{
reactorCool = dynamic_cast<CJetFlyingObject*>(m_object)->GetReactorRange() > 0.1f;
}
if ( motorSpeed.y > 0.0f && reactorCool && pos.y < h )
{
m_bLand = false; // take off
SetMotor(true);
@ -2103,7 +2093,7 @@ void CPhysics::SoundReactorFull(float rTime, ObjectType type)
m_soundChannelSlide = -1;
}
if ( m_reactorRange > 0.0f )
if ( !m_object->Implements(ObjectInterfaceType::JetFlying) || dynamic_cast<CJetFlyingObject*>(m_object)->GetReactorRange() > 0.0f )
{
if ( m_soundChannel == -1 )
{
@ -2384,10 +2374,13 @@ void CPhysics::FloorAdapt(float aTime, float rTime,
if ( m_floorHeight == 0.0f ) // ground plate?
{
CMotionVehicle* motionVehicle = dynamic_cast<CMotionVehicle*>(m_motion);
if (motionVehicle != nullptr && motionVehicle->GetTraceDown())
CTraceDrawingObject* traceDrawing = nullptr;
if (m_object->Implements(ObjectInterfaceType::TraceDrawing))
traceDrawing = dynamic_cast<CTraceDrawingObject*>(m_object);
if (traceDrawing != nullptr && traceDrawing->GetTraceDown())
{
WheelParticle(motionVehicle->GetTraceColor(), motionVehicle->GetTraceWidth()*g_unit);
WheelParticle(traceDrawing->GetTraceColor(), traceDrawing->GetTraceWidth()*g_unit);
}
else
{
@ -2461,7 +2454,6 @@ void CPhysics::FloorAngle(const Math::Vector &pos, Math::Vector &angle)
int CPhysics::ObjectAdapt(const Math::Vector &pos, const Math::Vector &angle)
{
CPhysics* ph;
Math::Matrix matRotate;
Math::Vector iPos, oAngle, oSpeed;
float distance, force, volume;
@ -2616,8 +2608,11 @@ int CPhysics::ObjectAdapt(const Math::Vector &pos, const Math::Vector &angle)
m_linMotion.currentSpeed.y = 0.0f;
}
ph = pObj->GetPhysics();
if ( ph != 0 )
CPhysics* ph = nullptr;
if (pObj->Implements(ObjectInterfaceType::Movable))
ph = dynamic_cast<CMovableObject*>(pObj)->GetPhysics();
if ( ph != nullptr )
{
oAngle = pObj->GetRotation();
oSpeed = Normalize(oPos-iPos)*force;
@ -3281,7 +3276,7 @@ void CPhysics::MotorParticle(float aTime, float rTime)
}
else // in flight?
{
if ( !m_bMotor || m_reactorRange == 0.0f ) return;
if ( !m_bMotor || (m_object->Implements(ObjectInterfaceType::JetFlying) && dynamic_cast<CJetFlyingObject*>(m_object)->GetReactorRange() == 0.0f) ) return;
if ( m_reactorTemperature < 1.0f ) // not too hot?
{
@ -3411,7 +3406,7 @@ void CPhysics::MotorParticle(float aTime, float rTime)
}
else // in flight?
{
if ( !m_bMotor || m_reactorRange == 0.0f ) return;
if ( !m_bMotor || (m_object->Implements(ObjectInterfaceType::JetFlying) && dynamic_cast<CJetFlyingObject*>(m_object)->GetReactorRange() == 0.0f) ) return;
if ( aTime-m_lastMotorParticle < m_engine->ParticleAdapt(0.02f) ) return;
m_lastMotorParticle = aTime;

View File

@ -30,7 +30,8 @@
#include "math/vector.h"
#include "object/object_type.h"
#include "object/trace_color.h"
#include "object/interface/trace_drawing_object.h"
class CObject;
@ -148,8 +149,6 @@ public:
bool GetCollision();
void SetFreeze(bool bFreeze);
bool GetFreeze();
void SetReactorRange(float range);
float GetReactorRange();
void SetMotorSpeed(Math::Vector speed);
void SetMotorSpeedX(float speed);
@ -236,7 +235,6 @@ protected:
Math::Vector m_wheelParticlePos[2];
float m_absorbWater;
float m_reactorTemperature;
float m_reactorRange;
float m_timeReactorFail;
float m_timeUnderWater;
float m_lastEnergy;

View File

@ -38,7 +38,6 @@
#include "object/object.h"
#include "object/object_manager.h"
#include "object/robotmain.h"
#include "object/trace_color.h"
#include "object/auto/auto.h"
#include "object/auto/autobase.h"
@ -46,11 +45,10 @@
#include "object/interface/programmable_object.h"
#include "object/interface/task_executor_object.h"
#include "object/interface/trace_drawing_object.h"
#include "object/level/parser.h"
#include "object/motion/motionvehicle.h"
#include "object/subclass/exchange_post.h"
#include "object/task/taskmanager.h"
@ -2886,8 +2884,18 @@ bool CScriptFunctions::rPenDown(CBotVar* var, CBotVar* result, int& exception, v
float width;
Error err;
CMotionVehicle* motionVehicle = dynamic_cast<CMotionVehicle*>(pThis->GetMotion());
assert(motionVehicle != nullptr);
if (!pThis->Implements(ObjectInterfaceType::TraceDrawing))
{
result->SetValInt(ERR_WRONG_OBJ);
if ( script->m_errMode == ERM_STOP )
{
exception = ERR_WRONG_OBJ;
return false;
}
return true;
}
CTraceDrawingObject* traceDrawing = dynamic_cast<CTraceDrawingObject*>(pThis);
exception = 0;
@ -2896,7 +2904,7 @@ bool CScriptFunctions::rPenDown(CBotVar* var, CBotVar* result, int& exception, v
color = var->GetValInt();
if ( color < 0 ) color = 0;
if ( color > static_cast<int>(TraceColor::Max) ) color = static_cast<int>(TraceColor::Max);
motionVehicle->SetTraceColor(static_cast<TraceColor>(color));
traceDrawing->SetTraceColor(static_cast<TraceColor>(color));
var = var->GetNext();
if ( var != 0 )
@ -2904,16 +2912,16 @@ bool CScriptFunctions::rPenDown(CBotVar* var, CBotVar* result, int& exception, v
width = var->GetValFloat();
if ( width < 0.1f ) width = 0.1f;
if ( width > 1.0f ) width = 1.0f;
motionVehicle->SetTraceWidth(width);
traceDrawing->SetTraceWidth(width);
}
}
motionVehicle->SetTraceDown(true);
traceDrawing->SetTraceDown(true);
if ( pThis->GetType() == OBJECT_MOBILEdr )
{
if ( !script->m_taskExecutor->IsForegroundTask() ) // no task in progress?
{
err = script->m_taskExecutor->StartTaskPen(motionVehicle->GetTraceDown(), motionVehicle->GetTraceColor());
err = script->m_taskExecutor->StartTaskPen(traceDrawing->GetTraceDown(), traceDrawing->GetTraceColor());
if ( err != ERR_OK )
{
script->m_taskExecutor->StopForegroundTask();
@ -2942,20 +2950,27 @@ bool CScriptFunctions::rPenUp(CBotVar* var, CBotVar* result, int& exception, voi
CObject* pThis = script->m_object;
Error err;
CMotionVehicle* motionVehicle = dynamic_cast<CMotionVehicle*>(pThis->GetMotion());
assert(motionVehicle != nullptr);
exception = 0;
motionVehicle->SetTraceDown(false);
if (!pThis->Implements(ObjectInterfaceType::TraceDrawing))
{
result->SetValInt(ERR_WRONG_OBJ);
if ( script->m_errMode == ERM_STOP )
{
exception = ERR_WRONG_OBJ;
return false;
}
return true;
}
CTraceDrawingObject* traceDrawing = dynamic_cast<CTraceDrawingObject*>(pThis);
traceDrawing->SetTraceDown(false);
if ( pThis->GetType() == OBJECT_MOBILEdr )
{
if ( !script->m_taskExecutor->IsForegroundTask() ) // no task in progress?
{
motionVehicle->SetTraceDown(false);
err = script->m_taskExecutor->StartTaskPen(motionVehicle->GetTraceDown(), motionVehicle->GetTraceColor());
err = script->m_taskExecutor->StartTaskPen(traceDrawing->GetTraceDown(), traceDrawing->GetTraceColor());
if ( err != ERR_OK )
{
script->m_taskExecutor->StopForegroundTask();
@ -2985,21 +3000,31 @@ bool CScriptFunctions::rPenColor(CBotVar* var, CBotVar* result, int& exception,
int color;
Error err;
CMotionVehicle* motionVehicle = dynamic_cast<CMotionVehicle*>(pThis->GetMotion());
assert(motionVehicle != nullptr);
exception = 0;
if (!pThis->Implements(ObjectInterfaceType::TraceDrawing))
{
result->SetValInt(ERR_WRONG_OBJ);
if ( script->m_errMode == ERM_STOP )
{
exception = ERR_WRONG_OBJ;
return false;
}
return true;
}
CTraceDrawingObject* traceDrawing = dynamic_cast<CTraceDrawingObject*>(pThis);
color = var->GetValInt();
if ( color < 0 ) color = 0;
if ( color > static_cast<int>(TraceColor::Max) ) color = static_cast<int>(TraceColor::Max);
motionVehicle->SetTraceColor(static_cast<TraceColor>(color));
traceDrawing->SetTraceColor(static_cast<TraceColor>(color));
if ( pThis->GetType() == OBJECT_MOBILEdr )
{
if ( !script->m_taskExecutor->IsForegroundTask() ) // no task in progress?
{
err = script->m_taskExecutor->StartTaskPen(motionVehicle->GetTraceDown(), motionVehicle->GetTraceColor());
err = script->m_taskExecutor->StartTaskPen(traceDrawing->GetTraceDown(), traceDrawing->GetTraceColor());
if ( err != ERR_OK )
{
script->m_taskExecutor->StopForegroundTask();
@ -3024,16 +3049,29 @@ bool CScriptFunctions::rPenColor(CBotVar* var, CBotVar* result, int& exception,
bool CScriptFunctions::rPenWidth(CBotVar* var, CBotVar* result, int& exception, void* user)
{
CObject* pThis = static_cast<CScript*>(user)->m_object;
CScript* script = static_cast<CScript*>(user);
CObject* pThis = script->m_object;
float width;
CMotionVehicle* motionVehicle = dynamic_cast<CMotionVehicle*>(pThis->GetMotion());
assert(motionVehicle != nullptr);
exception = 0;
if (!pThis->Implements(ObjectInterfaceType::TraceDrawing))
{
result->SetValInt(ERR_WRONG_OBJ);
if ( script->m_errMode == ERM_STOP )
{
exception = ERR_WRONG_OBJ;
return false;
}
return true;
}
CTraceDrawingObject* traceDrawing = dynamic_cast<CTraceDrawingObject*>(pThis);
width = var->GetValFloat();
if ( width < 0.1f ) width = 0.1f;
if ( width > 1.0f ) width = 1.0f;
motionVehicle->SetTraceWidth(width);
traceDrawing->SetTraceWidth(width);
return true;
}
@ -3843,8 +3881,8 @@ void CScriptFunctions::uObject(CBotVar* botThis, void* user)
// Updates the temperature of the reactor.
pVar = pVar->GetNext(); // "temperature"
if ( physics == 0 ) value = 0.0f;
else value = 1.0f-physics->GetReactorRange();
if ( !obj->Implements(ObjectInterfaceType::JetFlying) ) value = 0.0f;
else value = 1.0f-dynamic_cast<CJetFlyingObject*>(object)->GetReactorRange();
pVar->SetValFloat(value);
// Updates the height above the ground.
@ -3869,7 +3907,7 @@ void CScriptFunctions::uObject(CBotVar* botThis, void* user)
}
else if (power->Implements(ObjectInterfaceType::Old))
{
pVar->SetPointer(dynamic_cast<COldObject*>(power)->GetBotVar());
pVar->SetPointer(power->GetBotVar());
}
}
@ -3884,7 +3922,7 @@ void CScriptFunctions::uObject(CBotVar* botThis, void* user)
}
else if (cargo->Implements(ObjectInterfaceType::Old))
{
pVar->SetPointer(dynamic_cast<COldObject*>(cargo)->GetBotVar());
pVar->SetPointer(cargo->GetBotVar());
}
}

View File

@ -37,6 +37,8 @@
#include "object/object_manager.h"
#include "object/robotmain.h"
#include "object/interface/movable_object.h"
#include "object/motion/motion.h"
#include "object/motion/motiontoto.h"
@ -74,7 +76,7 @@ CDisplayInfo::CDisplayInfo()
m_infoFinalDim = m_infoActualPos = m_infoNormalDim = Math::Point(1.00f, 1.00f);
m_lightSuppl = -1;
m_toto = 0;
m_toto = nullptr;
m_bSoluce = false;
m_initPause = PAUSE_NONE;
m_bEditLock = false;
@ -96,7 +98,6 @@ bool CDisplayInfo::EventProcess(const Event &event)
Ui::CWindow* pw;
Ui::CEdit* edit;
Ui::CSlider* slider;
CMotionToto* toto;
if ( event.type == EVENT_FRAME )
{
@ -106,13 +107,12 @@ bool CDisplayInfo::EventProcess(const Event &event)
if ( event.type == EVENT_MOUSE_MOVE )
{
if ( m_toto != 0 )
if ( m_toto != nullptr )
{
toto = static_cast<CMotionToto*>(m_toto->GetMotion());
if ( toto != 0 )
{
toto->SetMousePos(event.mousePos);
}
assert(m_toto->Implements(ObjectInterfaceType::Movable));
CMotionToto* toto = static_cast<CMotionToto*>(dynamic_cast<CMovableObject*>(m_toto)->GetMotion());
assert(toto != nullptr);
toto->SetMousePos(event.mousePos);
}
}
@ -346,7 +346,6 @@ void CDisplayInfo::StartDisplayInfo(std::string filename, int index, bool bSoluc
Ui::CEdit* edit;
Ui::CButton* button;
Ui::CSlider* slider;
CMotionToto* toto;
m_index = index;
m_bSoluce = bSoluce;
@ -446,15 +445,14 @@ void CDisplayInfo::StartDisplayInfo(std::string filename, int index, bool bSoluc
m_particle->SetFrameUpdate(Gfx::SH_WORLD, false); // particles break into world
m_toto = SearchToto();
if ( m_toto != 0 )
if ( m_toto != nullptr )
{
m_toto->SetDrawFront(true);
toto = static_cast<CMotionToto*>(m_toto->GetMotion());
if ( toto != 0 )
{
toto->StartDisplayInfo();
}
assert(m_toto->Implements(ObjectInterfaceType::Movable));
CMotionToto* toto = static_cast<CMotionToto*>(dynamic_cast<CMovableObject*>(m_toto)->GetMotion());
assert(toto != nullptr);
toto->StartDisplayInfo();
}
light.type = Gfx::LIGHT_DIRECTIONAL;
@ -814,7 +812,6 @@ void CDisplayInfo::UpdateCopyButton()
void CDisplayInfo::StopDisplayInfo()
{
Ui::CWindow* pw;
CMotionToto* toto;
pw = static_cast<Ui::CWindow*>(m_interface->SearchControl(EVENT_WINDOW4));
if ( pw == 0 ) return;
@ -842,13 +839,12 @@ void CDisplayInfo::StopDisplayInfo()
m_particle->FlushParticle(Gfx::SH_FRONT);
m_particle->FlushParticle(Gfx::SH_INTERFACE);
if ( m_toto != 0 )
if ( m_toto != nullptr )
{
toto = static_cast<CMotionToto*>(m_toto->GetMotion());
if ( toto != 0 )
{
toto->StopDisplayInfo();
}
assert(m_toto->Implements(ObjectInterfaceType::Movable));
CMotionToto* toto = static_cast<CMotionToto*>(dynamic_cast<CMovableObject*>(m_toto)->GetMotion());
assert(toto != nullptr);
toto->StopDisplayInfo();
}
m_light->DeleteLight(m_lightSuppl);

View File

@ -30,6 +30,8 @@
#include "object/object.h"
#include "object/object_manager.h"
#include "object/interface/movable_object.h"
#include "object/motion/motion.h"
#include "object/motion/motiontoto.h"
@ -250,27 +252,26 @@ void CDisplayText::DisplayText(const char *text, Math::Vector goal, float height
m_textLines[nLine] = line;
toto = SearchToto();
if ( toto != 0 )
if ( toto != nullptr )
{
motion = toto->GetMotion();
if ( motion != 0 )
assert(toto->Implements(ObjectInterfaceType::Movable));
motion = dynamic_cast<CMovableObject*>(toto)->GetMotion();
if ( type == TT_ERROR )
{
if ( type == TT_ERROR )
{
motion->SetAction(MT_ERROR, 4.0f);
}
if ( type == TT_WARNING )
{
motion->SetAction(MT_WARNING, 4.0f);
}
if ( type == TT_INFO )
{
motion->SetAction(MT_INFO, 4.0f);
}
if ( type == TT_MESSAGE )
{
motion->SetAction(MT_MESSAGE, 4.0f);
}
motion->SetAction(MT_ERROR, 4.0f);
}
if ( type == TT_WARNING )
{
motion->SetAction(MT_WARNING, 4.0f);
}
if ( type == TT_INFO )
{
motion->SetAction(MT_INFO, 4.0f);
}
if ( type == TT_MESSAGE )
{
motion->SetAction(MT_MESSAGE, 4.0f);
}
}

View File

@ -887,14 +887,7 @@ bool CObjectInterface::CreateInterface(bool bSelect)
}
}
if ( type == OBJECT_HUMAN ||
type == OBJECT_MOBILEfa ||
type == OBJECT_MOBILEfc ||
type == OBJECT_MOBILEfi ||
type == OBJECT_MOBILEfs ||
type == OBJECT_MOBILEft ||
type == OBJECT_BEE ||
type == OBJECT_CONTROLLER) // driving?
if ( m_object->Implements(ObjectInterfaceType::Flying) )
{
pos.x = ox+sx*6.4f;
pos.y = oy+sy*0;
@ -906,15 +899,16 @@ bool CObjectInterface::CreateInterface(bool bSelect)
pb = pw->CreateButton(pos, dim, 28, EVENT_OBJECT_GASUP);
pb->SetImmediat(true);
if ( (type != OBJECT_HUMAN &&
type != OBJECT_CONTROLLER) ||
m_object->GetOption() != 2 )
if ( m_object->Implements(ObjectInterfaceType::JetFlying) )
{
pos.x = ox+sx*15.3f;
pos.y = oy+sy*0;
ddim.x = 14.0f/640.0f;
ddim.y = 66.0f/480.0f;
pw->CreateGauge(pos, ddim, 2, EVENT_OBJECT_GRANGE);
if ( type != OBJECT_HUMAN || m_object->GetOption() != 2 ) // if not Me without a jetpack, display reactor temperature
{
pos.x = ox+sx*15.3f;
pos.y = oy+sy*0;
ddim.x = 14.0f/640.0f;
ddim.y = 66.0f/480.0f;
pw->CreateGauge(pos, ddim, 2, EVENT_OBJECT_GRANGE);
}
}
}
@ -1544,8 +1538,9 @@ void CObjectInterface::UpdateInterface(float rTime)
pg = static_cast< CGauge* >(pw->SearchControl(EVENT_OBJECT_GRANGE));
if ( pg != 0 )
{
assert(m_object->Implements(ObjectInterfaceType::JetFlying));
icon = 2; // blue/red
range = m_physics->GetReactorRange();
range = dynamic_cast<CJetFlyingObject*>(m_object)->GetReactorRange();
if ( range < 0.2f && range != 0.0f && !m_physics->GetLand() )
{
@ -1863,8 +1858,10 @@ void CObjectInterface::UpdateInterface()
CheckInterface(pw, EVENT_OBJECT_MFRONT, m_manipStyle==EVENT_OBJECT_MFRONT);
}
CMotionVehicle* motionVehicle = dynamic_cast<CMotionVehicle*>(m_motion);
if (motionVehicle != nullptr && motionVehicle->GetTraceDown())
CTraceDrawingObject* traceDrawing = nullptr;
if (m_object->Implements(ObjectInterfaceType::TraceDrawing))
traceDrawing = dynamic_cast<CTraceDrawingObject*>(m_object);
if (traceDrawing != nullptr && traceDrawing->GetTraceDown())
{
pb = static_cast< CButton* >(pw->SearchControl(EVENT_OBJECT_PEN0));
if ( pb != 0 )
@ -1872,7 +1869,7 @@ void CObjectInterface::UpdateInterface()
pb->ClearState(STATE_CHECK);
}
TraceColor color = motionVehicle->GetTraceColor();
TraceColor color = traceDrawing->GetTraceColor();
pc = static_cast< CColor* >(pw->SearchControl(EVENT_OBJECT_PEN1));
if ( pc != 0 )
{