CFlyingObject; CJetFlyingObject

master
krzys-h 2015-08-12 19:09:35 +02:00
parent 1b73830f28
commit 5d52214737
22 changed files with 197 additions and 148 deletions

View File

@ -655,7 +655,6 @@ bool CAutoFactory::CreateVehicle()
CObject* vehicle = CObjectManager::GetInstancePointer()->CreateObject(params); CObject* vehicle = CObjectManager::GetInstancePointer()->CreateObject(params);
vehicle->SetLock(true); // not usable vehicle->SetLock(true); // not usable
vehicle->SetRange(30.0f);
CPhysics* physics = vehicle->GetPhysics(); CPhysics* physics = vehicle->GetPhysics();
if ( physics != nullptr ) if ( physics != nullptr )

View File

@ -52,8 +52,7 @@ CProgrammableObjectImpl::CProgrammableObjectImpl(ObjectInterfaceTypes& types, CO
, m_soluceName("") , m_soluceName("")
, m_traceRecord(false) , m_traceRecord(false)
{ {
assert(m_object != nullptr); //assert(m_object->Implements(ObjectInterfaceType::TaskExecutor));
assert(m_object->Implements(ObjectInterfaceType::TaskExecutor));
} }
CProgrammableObjectImpl::~CProgrammableObjectImpl() CProgrammableObjectImpl::~CProgrammableObjectImpl()

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"
#include "object/interface/movable_object.h"
/**
* \class CFlyingObject
* \brief Interface for objects that can fly
*/
class CFlyingObject : CMovableObject
{
public:
explicit CFlyingObject(ObjectInterfaceTypes& types)
: CMovableObject(types)
{
types[static_cast<int>(ObjectInterfaceType::Flying)] = true;
}
virtual ~CFlyingObject()
{}
};

View File

@ -0,0 +1,45 @@
/*
* 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"
#include "object/interface/flying_object.h"
/**
* \class CJetFlyingObject
* \brief Interface for objects that can fly using a jet engine
*/
class CJetFlyingObject : CFlyingObject
{
public:
explicit CJetFlyingObject(ObjectInterfaceTypes& types)
: CFlyingObject(types)
{
types[static_cast<int>(ObjectInterfaceType::JetFlying)] = true;
}
virtual ~CJetFlyingObject()
{}
//! 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;
};

View File

@ -330,8 +330,6 @@ void CMotionAnt::CreatePhysics()
-35,35,0, -25,40,0, -40,65,0, // s7: feet 1..3 -35,35,0, -25,40,0, -40,65,0, // s7: feet 1..3
}; };
m_physics->SetType(TYPE_ROLLING);
character = m_object->GetCharacter(); character = m_object->GetCharacter();
character->wheelFront = 3.0f; character->wheelFront = 3.0f;
character->wheelBack = 3.0f; character->wheelBack = 3.0f;

View File

@ -310,8 +310,6 @@ void CMotionBee::CreatePhysics()
-110,75,-15, -130,80,-25, -125,40,0, // s2: feet 1..3 -110,75,-15, -130,80,-25, -125,40,0, // s2: feet 1..3
}; };
m_physics->SetType(TYPE_FLYING);
character = m_object->GetCharacter(); character = m_object->GetCharacter();
character->wheelFront = 3.0f; character->wheelFront = 3.0f;
character->wheelBack = 3.0f; character->wheelBack = 3.0f;

View File

@ -501,8 +501,6 @@ void CMotionHuman::CreatePhysics(ObjectType type)
0,20,0, -10,5,5, 0,0,0, // s15: hands/feet/- 0,20,0, -10,5,5, 0,0,0, // s15: hands/feet/-
}; };
m_physics->SetType(TYPE_FLYING);
character = m_object->GetCharacter(); character = m_object->GetCharacter();
character->wheelFront = 4.0f; character->wheelFront = 4.0f;
character->wheelBack = 4.0f; character->wheelBack = 4.0f;

View File

@ -59,8 +59,6 @@ void CMotionLevelController::Create(Math::Vector pos, float angle, ObjectType ty
m_object->SetObjectRank(0, rank); m_object->SetObjectRank(0, rank);
// Movement // Movement
m_physics->SetType(TYPE_FLYING);
m_physics->SetLinMotionX(MO_ADVSPEED, 50.0f); m_physics->SetLinMotionX(MO_ADVSPEED, 50.0f);
m_physics->SetLinMotionX(MO_RECSPEED, 50.0f); m_physics->SetLinMotionX(MO_RECSPEED, 50.0f);
m_physics->SetLinMotionX(MO_ADVACCEL, 20.0f); m_physics->SetLinMotionX(MO_ADVACCEL, 20.0f);
@ -83,4 +81,3 @@ void CMotionLevelController::Create(Math::Vector pos, float angle, ObjectType ty
m_physics->SetCirMotionY(MO_RECACCEL, 2.0f); m_physics->SetCirMotionY(MO_RECACCEL, 2.0f);
m_physics->SetCirMotionY(MO_STOACCEL, 2.0f); m_physics->SetCirMotionY(MO_STOACCEL, 2.0f);
} }

View File

@ -270,8 +270,6 @@ void CMotionQueen::CreatePhysics()
0,0,0, 0,0,0, 0,0,0, // t2: unused 0,0,0, 0,0,0, 0,0,0, // t2: unused
}; };
m_physics->SetType(TYPE_ROLLING);
character = m_object->GetCharacter(); character = m_object->GetCharacter();
character->wheelFront = 10.0f; character->wheelFront = 10.0f;
character->wheelBack = 10.0f; character->wheelBack = 10.0f;

View File

@ -265,8 +265,6 @@ void CMotionSpider::CreatePhysics()
-5,0,0, -5,0,0, -5,0,0, -5,0,0, // s5: fingers 1..4 -5,0,0, -5,0,0, -5,0,0, -5,0,0, // s5: fingers 1..4
}; };
m_physics->SetType(TYPE_ROLLING);
character = m_object->GetCharacter(); character = m_object->GetCharacter();
character->wheelFront = 4.0f; character->wheelFront = 4.0f;
character->wheelBack = 4.0f; character->wheelBack = 4.0f;

View File

@ -968,8 +968,6 @@ void CMotionVehicle::CreatePhysics(ObjectType type)
type == OBJECT_MOBILEws || type == OBJECT_MOBILEws ||
type == OBJECT_MOBILEwt ) // wheels? type == OBJECT_MOBILEwt ) // wheels?
{ {
m_physics->SetType(TYPE_ROLLING);
character->wheelFront = 3.0f; character->wheelFront = 3.0f;
character->wheelBack = 4.0f; character->wheelBack = 4.0f;
character->wheelLeft = 4.0f; character->wheelLeft = 4.0f;
@ -996,8 +994,6 @@ void CMotionVehicle::CreatePhysics(ObjectType type)
if ( type == OBJECT_MOBILEtg ) if ( type == OBJECT_MOBILEtg )
{ {
m_physics->SetType(TYPE_ROLLING);
character->wheelFront = 4.0f; character->wheelFront = 4.0f;
character->wheelBack = 3.0f; character->wheelBack = 3.0f;
character->wheelLeft = 4.0f; character->wheelLeft = 4.0f;
@ -1027,8 +1023,6 @@ void CMotionVehicle::CreatePhysics(ObjectType type)
type == OBJECT_MOBILEti || type == OBJECT_MOBILEti ||
type == OBJECT_MOBILEts ) // caterpillars? type == OBJECT_MOBILEts ) // caterpillars?
{ {
m_physics->SetType(TYPE_ROLLING);
character->wheelFront = 4.0f; character->wheelFront = 4.0f;
character->wheelBack = 4.0f; character->wheelBack = 4.0f;
character->wheelLeft = 4.8f; character->wheelLeft = 4.8f;
@ -1058,8 +1052,6 @@ void CMotionVehicle::CreatePhysics(ObjectType type)
type == OBJECT_MOBILEii || type == OBJECT_MOBILEii ||
type == OBJECT_MOBILEis ) // legs? type == OBJECT_MOBILEis ) // legs?
{ {
m_physics->SetType(TYPE_ROLLING);
character->wheelFront = 4.0f; character->wheelFront = 4.0f;
character->wheelBack = 4.0f; character->wheelBack = 4.0f;
character->wheelLeft = 5.0f; character->wheelLeft = 5.0f;
@ -1091,8 +1083,6 @@ void CMotionVehicle::CreatePhysics(ObjectType type)
type == OBJECT_MOBILEfs || type == OBJECT_MOBILEfs ||
type == OBJECT_MOBILEft ) // flying? type == OBJECT_MOBILEft ) // flying?
{ {
m_physics->SetType(TYPE_FLYING);
character->wheelFront = 5.0f; character->wheelFront = 5.0f;
character->wheelBack = 4.0f; character->wheelBack = 4.0f;
character->wheelLeft = 4.5f; character->wheelLeft = 4.5f;
@ -1127,8 +1117,6 @@ void CMotionVehicle::CreatePhysics(ObjectType type)
type == OBJECT_MOBILErr || type == OBJECT_MOBILErr ||
type == OBJECT_MOBILErs ) // large caterpillars? type == OBJECT_MOBILErs ) // large caterpillars?
{ {
m_physics->SetType(TYPE_ROLLING);
character->wheelFront = 5.0f; character->wheelFront = 5.0f;
character->wheelBack = 5.0f; character->wheelBack = 5.0f;
character->wheelLeft = 6.0f; character->wheelLeft = 6.0f;
@ -1155,8 +1143,6 @@ void CMotionVehicle::CreatePhysics(ObjectType type)
if ( type == OBJECT_MOBILEsa ) if ( type == OBJECT_MOBILEsa )
{ {
m_physics->SetType(TYPE_ROLLING);
character->wheelFront = 4.0f; character->wheelFront = 4.0f;
character->wheelBack = 4.0f; character->wheelBack = 4.0f;
character->wheelLeft = 4.0f; character->wheelLeft = 4.0f;
@ -1183,8 +1169,6 @@ void CMotionVehicle::CreatePhysics(ObjectType type)
if ( type == OBJECT_MOBILEdr ) if ( type == OBJECT_MOBILEdr )
{ {
m_physics->SetType(TYPE_ROLLING);
character->wheelFront = 4.0f; character->wheelFront = 4.0f;
character->wheelBack = 4.0f; character->wheelBack = 4.0f;
character->wheelLeft = 4.0f; character->wheelLeft = 4.0f;
@ -1211,8 +1195,6 @@ void CMotionVehicle::CreatePhysics(ObjectType type)
if ( type == OBJECT_APOLLO2 ) // jeep? if ( type == OBJECT_APOLLO2 ) // jeep?
{ {
m_physics->SetType(TYPE_ROLLING);
character->wheelFront = 6.0f; character->wheelFront = 6.0f;
character->wheelBack = 6.0f; character->wheelBack = 6.0f;
character->wheelLeft = 5.0f; character->wheelLeft = 5.0f;

View File

@ -150,8 +150,6 @@ void CMotionWorm::CreatePhysics()
{ {
Character* character; Character* character;
m_physics->SetType(TYPE_ROLLING);
character = m_object->GetCharacter(); character = m_object->GetCharacter();
character->wheelFront = 10.0f; character->wheelFront = 10.0f;
character->wheelBack = 10.0f; character->wheelBack = 10.0f;
@ -356,4 +354,3 @@ bool CMotionWorm::EventFrame(const Event &event)
return true; return true;
} }

View File

@ -41,6 +41,8 @@ enum class ObjectInterfaceType
Carrier, //!< object that can carry other objects Carrier, //!< object that can carry other objects
Powered, //!< object powered with power cell Powered, //!< object powered with power cell
Movable, //!< objects that can move Movable, //!< objects that can move
Flying, //!< objects that can fly
JetFlying, //!< objects that can fly using a jet engine
Controllable, //!< objects that can be selected and controlled by the player Controllable, //!< objects that can be selected and controlled by the player
PowerContainer, //!< objects that hold power PowerContainer, //!< objects that hold power
Ranged, //!< objects that have a operation range to be displayed after pressing button in the UI Ranged, //!< objects that have a operation range to be displayed after pressing button in the UI

View File

@ -82,7 +82,7 @@ COldObject::COldObject(int id)
, CJostleableObject(m_implementedInterfaces) , CJostleableObject(m_implementedInterfaces)
, CCarrierObject(m_implementedInterfaces) , CCarrierObject(m_implementedInterfaces)
, CPoweredObject(m_implementedInterfaces) , CPoweredObject(m_implementedInterfaces)
, CMovableObject(m_implementedInterfaces) , CJetFlyingObject(m_implementedInterfaces)
, CControllableObject(m_implementedInterfaces) , CControllableObject(m_implementedInterfaces)
, CPowerContainerObjectImpl(m_implementedInterfaces, this) , CPowerContainerObjectImpl(m_implementedInterfaces, this)
, CRangedObject(m_implementedInterfaces) , CRangedObject(m_implementedInterfaces)
@ -116,7 +116,7 @@ COldObject::COldObject(int id)
m_transporter = 0; m_transporter = 0;
m_transporterLink = 0; m_transporterLink = 0;
m_shield = 1.0f; m_shield = 1.0f;
m_range = 0.0f; m_range = 30.0f;
m_transparency = 0.0f; m_transparency = 0.0f;
m_lastEnergy = 999.9f; m_lastEnergy = 999.9f;
m_bSelect = false; m_bSelect = false;
@ -658,6 +658,48 @@ void COldObject::SetType(ObjectType type)
m_param = 1.0f; // shield up to default m_param = 1.0f; // shield up to default
} }
// TODO: Temporary hack
if ( m_type == OBJECT_MOBILEfa || // WingedGrabber
m_type == OBJECT_MOBILEfs || // WingedSniffer
m_type == OBJECT_MOBILEfc || // WingedShooter
m_type == OBJECT_MOBILEfi || // WingedOrgaShooter
m_type == OBJECT_MOBILEft || // winged PracticeBot (unused)
m_type == OBJECT_HUMAN || // Me
m_type == OBJECT_TECH ) // Tech
{
m_implementedInterfaces[static_cast<int>(ObjectInterfaceType::Flying)] = true;
m_implementedInterfaces[static_cast<int>(ObjectInterfaceType::JetFlying)] = true;
}
else if ( m_type == OBJECT_BEE )
{
m_implementedInterfaces[static_cast<int>(ObjectInterfaceType::Flying)] = true;
m_implementedInterfaces[static_cast<int>(ObjectInterfaceType::JetFlying)] = false;
}
else
{
m_implementedInterfaces[static_cast<int>(ObjectInterfaceType::Flying)] = false;
m_implementedInterfaces[static_cast<int>(ObjectInterfaceType::JetFlying)] = false;
}
// TODO: Another temporary hack
if ( m_type == OBJECT_MOTHER ||
m_type == OBJECT_ANT ||
m_type == OBJECT_SPIDER ||
m_type == OBJECT_BEE ||
m_type == OBJECT_WORM ||
m_type == OBJECT_APOLLO2 ||
m_type == OBJECT_MOBILEdr ||
m_type == OBJECT_CONTROLLER ||
m_type == OBJECT_HUMAN ||
m_type == OBJECT_TECH )
{
m_implementedInterfaces[static_cast<int>(ObjectInterfaceType::Powered)] = false;
}
else
{
m_implementedInterfaces[static_cast<int>(ObjectInterfaceType::Powered)] = true;
}
if ( m_type == OBJECT_MOBILEwc || if ( m_type == OBJECT_MOBILEwc ||
m_type == OBJECT_MOBILEtc || m_type == OBJECT_MOBILEtc ||
m_type == OBJECT_MOBILEfc || m_type == OBJECT_MOBILEfc ||
@ -805,7 +847,6 @@ void COldObject::Read(CLevelParserLine* line)
SetCameraLock(line->GetParam("cameraLock")->AsBool(false)); SetCameraLock(line->GetParam("cameraLock")->AsBool(false));
SetEnergyLevel(line->GetParam("energy")->AsFloat(0.0f)); SetEnergyLevel(line->GetParam("energy")->AsFloat(0.0f));
SetShield(line->GetParam("shield")->AsFloat(1.0f)); SetShield(line->GetParam("shield")->AsFloat(1.0f));
SetRange(line->GetParam("range")->AsFloat(1.0f));
SetSelectable(line->GetParam("selectable")->AsBool(true)); SetSelectable(line->GetParam("selectable")->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));
@ -1060,7 +1101,7 @@ void COldObject::SetPartPosition(int part, const Math::Vector &pos)
m_engine->SetObjectShadowPos(rank, shPos); m_engine->SetObjectShadowPos(rank, shPos);
float height = 0.0f; float height = 0.0f;
if ( m_physics != nullptr && m_physics->GetType() == TYPE_FLYING ) if ( Implements(ObjectInterfaceType::Flying) )
{ {
height = pos.y-shPos.y; height = pos.y-shPos.y;
} }

View File

@ -28,7 +28,9 @@
#include "object/interface/carrier_object.h" #include "object/interface/carrier_object.h"
#include "object/interface/controllable_object.h" #include "object/interface/controllable_object.h"
#include "object/interface/flying_object.h"
#include "object/interface/interactive_object.h" #include "object/interface/interactive_object.h"
#include "object/interface/jet_flying_object.h"
#include "object/interface/jostleable_object.h" #include "object/interface/jostleable_object.h"
#include "object/interface/movable_object.h" #include "object/interface/movable_object.h"
#include "object/interface/power_container_object.h" #include "object/interface/power_container_object.h"
@ -77,7 +79,7 @@ class COldObject : public CObject,
public CJostleableObject, public CJostleableObject,
public CCarrierObject, public CCarrierObject,
public CPoweredObject, public CPoweredObject,
public CMovableObject, public CJetFlyingObject,
public CControllableObject, public CControllableObject,
public CPowerContainerObjectImpl, public CPowerContainerObjectImpl,
public CRangedObject public CRangedObject

View File

@ -115,16 +115,6 @@ float COldObjectInterface::GetShield()
} }
void COldObjectInterface::SetRange(float delay)
{
throw std::logic_error("SetRange: not implemented!");
}
float COldObjectInterface::GetRange()
{
throw std::logic_error("GetRange: not implemented!");
}
void COldObjectInterface::SetFixed(bool bFixed) void COldObjectInterface::SetFixed(bool bFixed)
{ {
throw std::logic_error("SetFixed: not implemented!"); throw std::logic_error("SetFixed: not implemented!");

View File

@ -99,10 +99,6 @@ public:
virtual void SetMagnifyDamage(float factor); virtual void SetMagnifyDamage(float factor);
virtual float GetMagnifyDamage(); virtual float GetMagnifyDamage();
// This goes to CFlyingObject (child of CMovableObject)
virtual void SetRange(float delay);
virtual float GetRange();
// This goes to CBaseAlien or something like that // This goes to CBaseAlien or something like that
virtual void SetFixed(bool bFixed); virtual void SetFixed(bool bFixed);
virtual bool GetFixed(); virtual bool GetFixed();

View File

@ -1208,8 +1208,8 @@ void CRobotMain::ExecuteCmd(char *cmd)
if (strcmp(cmd, "addfreezer") == 0) if (strcmp(cmd, "addfreezer") == 0)
{ {
CObject* object = GetSelect(); CObject* object = GetSelect();
if (object != nullptr) if (object != nullptr && object->Implements(ObjectInterfaceType::JetFlying))
object->SetRange(object->GetRange()*10.0f); dynamic_cast<CJetFlyingObject*>(object)->SetRange(dynamic_cast<CJetFlyingObject*>(object)->GetRange()*10.0f);
return; return;
} }

View File

@ -194,7 +194,7 @@ bool CTaskGoto::EventProcess(const Event &event)
pos = m_object->GetPosition(); pos = m_object->GetPosition();
if ( m_physics->GetType() == TYPE_FLYING && m_altitude == 0.0f ) if ( m_object->Implements(ObjectInterfaceType::Flying) && m_altitude == 0.0f )
{ {
if ( m_physics->GetLand() ) if ( m_physics->GetLand() )
{ {
@ -206,7 +206,7 @@ bool CTaskGoto::EventProcess(const Event &event)
} }
} }
if ( m_physics->GetType() == TYPE_FLYING && m_altitude > 0.0f ) if ( m_object->Implements(ObjectInterfaceType::Flying) && m_altitude > 0.0f )
{ {
goal = m_bmPoints[m_bmIndex]; goal = m_bmPoints[m_bmIndex];
goal.y = pos.y; goal.y = pos.y;
@ -345,7 +345,7 @@ bool CTaskGoto::EventProcess(const Event &event)
} }
if ( m_phase != TGP_TURN && if ( m_phase != TGP_TURN &&
m_physics->GetType() == TYPE_FLYING && m_object->Implements(ObjectInterfaceType::Flying) &&
m_altitude > 0.0f ) m_altitude > 0.0f )
{ {
pos = m_object->GetPosition(); pos = m_object->GetPosition();
@ -395,7 +395,7 @@ bool CTaskGoto::EventProcess(const Event &event)
a = m_object->GetRotationY(); a = m_object->GetRotationY();
g = Math::RotateAngle(rot.x, -rot.y); // CW ! g = Math::RotateAngle(rot.x, -rot.y); // CW !
cirSpeed = Math::Direction(a, g)*1.0f; cirSpeed = Math::Direction(a, g)*1.0f;
//? if ( m_physics->GetType() == TYPE_FLYING && //? if ( m_object->Implements(ObjectInterfaceType::Flying) &&
//? m_physics->GetLand() ) // flying on the ground? //? m_physics->GetLand() ) // flying on the ground?
//? { //? {
//? cirSpeed *= 4.0f; // more fishing //? cirSpeed *= 4.0f; // more fishing
@ -405,7 +405,7 @@ bool CTaskGoto::EventProcess(const Event &event)
dist = Math::DistanceProjected(m_goal, pos); dist = Math::DistanceProjected(m_goal, pos);
linSpeed = dist/(m_physics->GetLinStopLength()*1.5f); linSpeed = dist/(m_physics->GetLinStopLength()*1.5f);
//? if ( m_physics->GetType() == TYPE_FLYING && //? if ( m_object->Implements(ObjectInterfaceType::Flying) &&
//? m_physics->GetLand() ) // flying on the ground? //? m_physics->GetLand() ) // flying on the ground?
//? { //? {
//? linSpeed *= 8.0f; // more fishing //? linSpeed *= 8.0f; // more fishing
@ -708,7 +708,7 @@ Error CTaskGoto::Start(Math::Vector goal, float altitude,
m_bTake = true; // object was taken on arrival (final rotation) m_bTake = true; // object was taken on arrival (final rotation)
} }
if ( m_physics->GetType() == TYPE_FLYING && m_altitude == 0.0f ) if ( m_object->Implements(ObjectInterfaceType::Flying) && m_altitude == 0.0f )
{ {
pos = m_object->GetPosition(); pos = m_object->GetPosition();
dist = Math::DistanceProjected(pos, m_goal); dist = Math::DistanceProjected(pos, m_goal);
@ -773,7 +773,7 @@ Error CTaskGoto::IsEnded()
if ( m_phase == TGP_BEAMUP ) // off? if ( m_phase == TGP_BEAMUP ) // off?
{ {
if ( m_physics->GetType() == TYPE_FLYING && m_altitude > 0.0f ) if ( m_object->Implements(ObjectInterfaceType::Flying) && m_altitude > 0.0f )
{ {
level = m_terrain->GetFloorLevel(pos, true, true); level = m_terrain->GetFloorLevel(pos, true, true);
h = level+m_altitude-20.0f; h = level+m_altitude-20.0f;
@ -826,7 +826,7 @@ Error CTaskGoto::IsEnded()
if ( m_phase == TGP_BEAMDOWN ) // landed? if ( m_phase == TGP_BEAMDOWN ) // landed?
{ {
if ( m_physics->GetType() == TYPE_FLYING && m_altitude > 0.0f ) if ( m_object->Implements(ObjectInterfaceType::Flying) && m_altitude > 0.0f )
{ {
if ( !m_physics->GetLand() ) return ERR_CONTINUE; if ( !m_physics->GetLand() ) return ERR_CONTINUE;
m_physics->SetMotorSpeedY(0.0f); // stops the descent m_physics->SetMotorSpeedY(0.0f); // stops the descent
@ -877,7 +877,7 @@ Error CTaskGoto::IsEnded()
if ( m_phase == TGP_LAND ) // landed? if ( m_phase == TGP_LAND ) // landed?
{ {
if ( m_physics->GetType() == TYPE_FLYING && m_altitude > 0.0f ) if ( m_object->Implements(ObjectInterfaceType::Flying) && m_altitude > 0.0f )
{ {
if ( !m_physics->GetLand() ) return ERR_CONTINUE; if ( !m_physics->GetLand() ) return ERR_CONTINUE;
m_physics->SetMotorSpeedY(0.0f); m_physics->SetMotorSpeedY(0.0f);
@ -1259,7 +1259,7 @@ bool CTaskGoto::GetHotPoint(CObject *pObj, Math::Vector &pos,
return true; return true;
} }
if ( type == OBJECT_PARA && m_physics->GetType() == TYPE_FLYING ) if ( type == OBJECT_PARA && m_object->Implements(ObjectInterfaceType::Flying) )
{ {
mat = pObj->GetWorldMatrix(0); mat = pObj->GetWorldMatrix(0);
if ( bTake && distance != 0.0f ) suppl = 20.0f; if ( bTake && distance != 0.0f ) suppl = 20.0f;
@ -1818,7 +1818,7 @@ void CTaskGoto::BitmapObject()
if (IsObjectBeingTransported(pObj)) continue; if (IsObjectBeingTransported(pObj)) continue;
float h = m_terrain->GetFloorLevel(pObj->GetPosition(), false); float h = m_terrain->GetFloorLevel(pObj->GetPosition(), false);
if ( m_physics->GetType() == TYPE_FLYING && m_altitude > 0.0f ) if ( m_object->Implements(ObjectInterfaceType::Flying) && m_altitude > 0.0f )
{ {
h += m_altitude; h += m_altitude;
} }
@ -1828,7 +1828,7 @@ void CTaskGoto::BitmapObject()
Math::Vector oPos = crashSphere.sphere.pos; Math::Vector oPos = crashSphere.sphere.pos;
float oRadius = crashSphere.sphere.radius; float oRadius = crashSphere.sphere.radius;
if ( m_physics->GetType() == TYPE_FLYING && m_altitude > 0.0f ) // flying? if ( m_object->Implements(ObjectInterfaceType::Flying) && m_altitude > 0.0f ) // flying?
{ {
if ( oPos.y-oRadius > h+8.0f || if ( oPos.y-oRadius > h+8.0f ||
oPos.y+oRadius < h-8.0f ) continue; oPos.y+oRadius < h-8.0f ) continue;

View File

@ -88,7 +88,7 @@ bool CTaskManip::EventProcess(const Event &event)
a = m_object->GetRotationY(); a = m_object->GetRotationY();
g = m_angle; g = m_angle;
cirSpeed = Math::Direction(a, g)*1.0f; cirSpeed = Math::Direction(a, g)*1.0f;
if ( m_physics->GetType() == TYPE_FLYING ) // flying on the ground? if ( m_object->Implements(ObjectInterfaceType::Flying) ) // flying on the ground?
{ {
cirSpeed *= 4.0f; // more fishing cirSpeed *= 4.0f; // more fishing
} }

View File

@ -76,7 +76,6 @@ CPhysics::CPhysics(COldObject* object)
m_sound = CApplication::GetInstancePointer()->GetSound(); m_sound = CApplication::GetInstancePointer()->GetSound();
m_motion = nullptr; m_motion = nullptr;
m_type = TYPE_ROLLING;
m_gravity = 9.81f; // default gravity m_gravity = 9.81f; // default gravity
m_time = 0.0f; m_time = 0.0f;
m_timeUnderWater = 0.0f; m_timeUnderWater = 0.0f;
@ -154,19 +153,6 @@ void CPhysics::SetMotion(CMotion* motion)
m_motion = motion; m_motion = motion;
} }
// Management of the type.
void CPhysics::SetType(PhysicsType type)
{
m_type = type;
}
PhysicsType CPhysics::GetType()
{
return m_type;
}
// Saves all parameters of the object. // Saves all parameters of the object.
@ -174,9 +160,12 @@ bool CPhysics::Write(CLevelParserLine* line)
{ {
line->AddParam("motor", MakeUnique<CLevelParserParam>(m_motorSpeed)); line->AddParam("motor", MakeUnique<CLevelParserParam>(m_motorSpeed));
if ( m_type == TYPE_FLYING ) if ( m_object->Implements(ObjectInterfaceType::Flying) )
{ {
line->AddParam("reactorRange", MakeUnique<CLevelParserParam>(GetReactorRange())); if ( m_object->Implements(ObjectInterfaceType::JetFlying) )
{
line->AddParam("reactorRange", MakeUnique<CLevelParserParam>(GetReactorRange()));
}
line->AddParam("land", MakeUnique<CLevelParserParam>(GetLand())); line->AddParam("land", MakeUnique<CLevelParserParam>(GetLand()));
} }
@ -189,9 +178,12 @@ bool CPhysics::Read(CLevelParserLine* line)
{ {
m_motorSpeed = line->GetParam("motor")->AsPoint(); m_motorSpeed = line->GetParam("motor")->AsPoint();
if ( m_type == TYPE_FLYING ) if ( m_object->Implements(ObjectInterfaceType::Flying) )
{ {
SetReactorRange(line->GetParam("reactorRange")->AsFloat()); if ( m_object->Implements(ObjectInterfaceType::JetFlying) )
{
SetReactorRange(line->GetParam("reactorRange")->AsFloat());
}
SetLand(line->GetParam("land")->AsBool()); SetLand(line->GetParam("land")->AsBool());
} }
@ -662,7 +654,7 @@ float CPhysics::GetLinStopLength(PhysicsMode sMode, PhysicsMode aMode)
speed = GetLinMotionX(sMode); // MO_ADVSPEED/MO_RECSPEED speed = GetLinMotionX(sMode); // MO_ADVSPEED/MO_RECSPEED
accel = GetLinMotionX(aMode); // MO_ADVACCEL/MO_RECACCEL/MO_STOACCEL accel = GetLinMotionX(aMode); // MO_ADVACCEL/MO_RECACCEL/MO_STOACCEL
if ( m_type == TYPE_FLYING && m_bLand ) // flying on the ground? if ( m_object->Implements(ObjectInterfaceType::Flying) && m_bLand ) // flying on the ground?
{ {
speed /= LANDING_SPEED; speed /= LANDING_SPEED;
accel *= LANDING_ACCEL; accel *= LANDING_ACCEL;
@ -688,7 +680,7 @@ float CPhysics::GetLinMaxLength(float dir)
if ( dir > 0.0f ) dist = m_linMotion.advanceSpeed.x; if ( dir > 0.0f ) dist = m_linMotion.advanceSpeed.x;
else dist = m_linMotion.recedeSpeed.x; else dist = m_linMotion.recedeSpeed.x;
if ( m_type == TYPE_FLYING ) if ( m_object->Implements(ObjectInterfaceType::Flying) )
{ {
dist /= 5.0f; dist /= 5.0f;
} }
@ -784,21 +776,9 @@ void CPhysics::MotorUpdate(float aTime, float rTime)
motorSpeed = m_motorSpeed; motorSpeed = m_motorSpeed;
if ( type == OBJECT_MOTHER || if ( type == OBJECT_HUMAN ||
type == OBJECT_ANT || type == OBJECT_TECH )
type == OBJECT_SPIDER ||
type == OBJECT_BEE ||
type == OBJECT_WORM ||
type == OBJECT_APOLLO2 ||
type == OBJECT_MOBILEdr ||
type == OBJECT_CONTROLLER)
{ {
power = nullptr;
}
else if ( type == OBJECT_HUMAN ||
type == OBJECT_TECH )
{
power = nullptr;
if (IsObjectCarryingCargo(m_object) && // carries something? if (IsObjectCarryingCargo(m_object) && // carries something?
!m_bFreeze ) !m_bFreeze )
{ {
@ -829,26 +809,24 @@ void CPhysics::MotorUpdate(float aTime, float rTime)
} }
} }
} }
else
if (m_object->Implements(ObjectInterfaceType::Powered))
{ {
if (m_object->Implements(ObjectInterfaceType::Powered)) power = dynamic_cast<CPowerContainerObject*>(dynamic_cast<CPoweredObject*>(m_object)->GetPower()); // searches for the object battery uses
if ( GetObjectEnergy(m_object) == 0.0f ) // no battery or flat?
{ {
power = dynamic_cast<CPowerContainerObject*>(dynamic_cast<CPoweredObject*>(m_object)->GetPower()); // searches for the object battery uses motorSpeed.x = 0.0f;
if ( GetObjectEnergy(m_object) == 0.0f ) // no battery or flat? motorSpeed.z = 0.0f;
if ( m_bFreeze || m_bLand )
{ {
motorSpeed.x = 0.0f; motorSpeed.y = 0.0f; // immobile
motorSpeed.z = 0.0f;
if ( m_bFreeze || m_bLand )
{
motorSpeed.y = 0.0f; // immobile
}
else
{
motorSpeed.y = -1.0f; // grave
SetFalling();
}
SetMotor(false);
} }
else
{
motorSpeed.y = -1.0f; // grave
SetFalling();
}
SetMotor(false);
} }
} }
@ -867,7 +845,7 @@ void CPhysics::MotorUpdate(float aTime, float rTime)
SetMotor(false); SetMotor(false);
} }
if ( m_type == TYPE_FLYING && !m_bLand && motorSpeed.y > 0.0f ) if ( m_object->Implements(ObjectInterfaceType::Flying) && !m_bLand && motorSpeed.y > 0.0f )
{ {
pos = m_object->GetPosition(); pos = m_object->GetPosition();
h = m_terrain->GetFlyingLimit(pos, type==OBJECT_BEE); h = m_terrain->GetFlyingLimit(pos, type==OBJECT_BEE);
@ -881,8 +859,8 @@ void CPhysics::MotorUpdate(float aTime, float rTime)
} }
} }
if ( type != OBJECT_BEE && if ( m_object->Implements(ObjectInterfaceType::JetFlying) &&
m_object->GetRange() > 0.0f ) // limited flight range? dynamic_cast<CJetFlyingObject*>(m_object)->GetRange() > 0.0f ) // limited flight range?
{ {
if ( m_bLand || m_bSwim || m_bObstacle ) // on the ground or in the water? if ( m_bLand || m_bSwim || m_bObstacle ) // on the ground or in the water?
{ {
@ -903,7 +881,7 @@ void CPhysics::MotorUpdate(float aTime, float rTime)
} }
else // in flight? else // in flight?
{ {
m_reactorRange -= rTime*(1.0f/m_object->GetRange()); m_reactorRange -= rTime*(1.0f/dynamic_cast<CJetFlyingObject*>(m_object)->GetRange());
if ( m_reactorRange < 0.0f ) m_reactorRange = 0.0f; if ( m_reactorRange < 0.0f ) m_reactorRange = 0.0f;
if ( m_reactorRange < 0.5f ) m_bLowLevel = true; if ( m_reactorRange < 0.5f ) m_bLowLevel = true;
} }
@ -971,7 +949,7 @@ void CPhysics::MotorUpdate(float aTime, float rTime)
m_cirMotion.motorSpeed.y = 0.0f; m_cirMotion.motorSpeed.y = 0.0f;
} }
if ( m_type == TYPE_FLYING && m_bLand ) // flying on the ground? if ( m_object->Implements(ObjectInterfaceType::Flying) && m_bLand ) // flying on the ground?
{ {
if ( type == OBJECT_HUMAN || if ( type == OBJECT_HUMAN ||
type == OBJECT_TECH ) type == OBJECT_TECH )
@ -997,7 +975,7 @@ void CPhysics::MotorUpdate(float aTime, float rTime)
} }
} }
if ( m_type == TYPE_ROLLING ) if ( !m_object->Implements(ObjectInterfaceType::Flying) )
{ {
if ( motorSpeed.x == 0.0f && if ( motorSpeed.x == 0.0f &&
motorSpeed.z == 0.0f ) motorSpeed.z == 0.0f )
@ -1022,7 +1000,7 @@ void CPhysics::MotorUpdate(float aTime, float rTime)
energy -= fabs(motorSpeed.x)*rTime*factor*0.005f; energy -= fabs(motorSpeed.x)*rTime*factor*0.005f;
energy -= fabs(motorSpeed.z)*rTime*factor*0.005f; energy -= fabs(motorSpeed.z)*rTime*factor*0.005f;
if ( m_type == TYPE_FLYING && motorSpeed.y > 0.0f ) if ( m_object->Implements(ObjectInterfaceType::Flying) && motorSpeed.y > 0.0f )
{ {
energy -= motorSpeed.y*rTime*factor*0.01f; energy -= motorSpeed.y*rTime*factor*0.01f;
} }
@ -1550,7 +1528,7 @@ bool CPhysics::EventFrame(const Event &event)
m_terrain->AdjustToStandardBounds(newpos); m_terrain->AdjustToStandardBounds(newpos);
if ( m_type == TYPE_FLYING && !m_bLand ) if ( m_object->Implements(ObjectInterfaceType::Flying) && !m_bLand )
{ {
h = m_terrain->GetFlyingLimit(newpos, type==OBJECT_BEE); h = m_terrain->GetFlyingLimit(newpos, type==OBJECT_BEE);
h += m_object->GetCharacter()->height; h += m_object->GetCharacter()->height;
@ -1715,7 +1693,7 @@ void CPhysics::SoundMotor(float rTime)
} }
else // vehicle? else // vehicle?
{ {
if ( m_type == TYPE_ROLLING ) if ( !m_object->Implements(ObjectInterfaceType::Flying) )
{ {
if ( m_bMotor && m_object->GetActive() ) if ( m_bMotor && m_object->GetActive() )
{ {
@ -1737,7 +1715,7 @@ void CPhysics::SoundMotor(float rTime)
} }
} }
if ( m_type == TYPE_FLYING ) if ( m_object->Implements(ObjectInterfaceType::Flying) )
{ {
if ( m_bMotor && !m_bSwim && if ( m_bMotor && !m_bSwim &&
m_object->GetActive() && !m_object->GetDead() ) m_object->GetActive() && !m_object->GetDead() )
@ -2295,14 +2273,14 @@ void CPhysics::FloorAdapt(float aTime, float rTime,
fabs(m_linMotion.realSpeed.x), fabs(m_linMotion.realSpeed.x),
fabs(m_cirMotion.realSpeed.y*15.0f)); fabs(m_cirMotion.realSpeed.y*15.0f));
if ( m_type == TYPE_ROLLING ) if ( !m_object->Implements(ObjectInterfaceType::Flying) )
{ {
pos.y -= h; // plate to the ground immediately pos.y -= h; // plate to the ground immediately
pos.y += character->height; pos.y += character->height;
m_floorHeight = 0.0f; m_floorHeight = 0.0f;
} }
if ( m_type == TYPE_FLYING ) if ( m_object->Implements(ObjectInterfaceType::Flying) )
{ {
bSlopingTerrain = false; // ground as possible to land bSlopingTerrain = false; // ground as possible to land
@ -2423,7 +2401,7 @@ void CPhysics::FloorAdapt(float aTime, float rTime,
FloorAngle(pos, angle); // adjusts the angle at the ground FloorAngle(pos, angle); // adjusts the angle at the ground
if ( m_type == TYPE_FLYING && !m_bLand ) // flying in the air? if ( m_object->Implements(ObjectInterfaceType::Flying) && !m_bLand ) // flying in the air?
{ {
f = h/1.0f; f = h/1.0f;
if ( f < 0.0f ) f = 0.0f; if ( f < 0.0f ) f = 0.0f;
@ -2633,7 +2611,7 @@ int CPhysics::ObjectAdapt(const Math::Vector &pos, const Math::Vector &angle)
m_linMotion.currentSpeed = Normalize(iPos-oPos)*force; m_linMotion.currentSpeed = Normalize(iPos-oPos)*force;
Math::LoadRotationXZYMatrix(matRotate, -angle); Math::LoadRotationXZYMatrix(matRotate, -angle);
m_linMotion.currentSpeed = Transform(matRotate, m_linMotion.currentSpeed); m_linMotion.currentSpeed = Transform(matRotate, m_linMotion.currentSpeed);
if ( m_type == TYPE_ROLLING ) if ( !m_object->Implements(ObjectInterfaceType::Flying) )
{ {
m_linMotion.currentSpeed.y = 0.0f; m_linMotion.currentSpeed.y = 0.0f;
} }
@ -2645,7 +2623,7 @@ int CPhysics::ObjectAdapt(const Math::Vector &pos, const Math::Vector &angle)
oSpeed = Normalize(oPos-iPos)*force; oSpeed = Normalize(oPos-iPos)*force;
Math::LoadRotationXZYMatrix(matRotate, -oAngle); Math::LoadRotationXZYMatrix(matRotate, -oAngle);
oSpeed = Transform(matRotate, oSpeed); oSpeed = Transform(matRotate, oSpeed);
if ( ph->GetType() == TYPE_ROLLING ) if ( !pObj->Implements(ObjectInterfaceType::Flying) )
{ {
oSpeed.y = 0.0f; oSpeed.y = 0.0f;
} }
@ -3376,7 +3354,7 @@ void CPhysics::MotorParticle(float aTime, float rTime)
m_reactorTemperature = 0.0f; // reactor cold m_reactorTemperature = 0.0f; // reactor cold
} }
if ( m_type == TYPE_FLYING && if ( m_object->Implements(ObjectInterfaceType::Flying) &&
type != OBJECT_HUMAN && type != OBJECT_HUMAN &&
type != OBJECT_TECH && type != OBJECT_TECH &&
!m_bSwim ) !m_bSwim )
@ -3547,10 +3525,11 @@ void CPhysics::MotorParticle(float aTime, float rTime)
} }
} }
if ( m_type == TYPE_ROLLING ) if ( !m_object->Implements(ObjectInterfaceType::Flying) )
{ {
if ( type == OBJECT_APOLLO2 ) return; // electric motors! if ( type == OBJECT_APOLLO2 ) return; // electric motors!
// Create engine smoke
if ( type == OBJECT_MOBILErt || if ( type == OBJECT_MOBILErt ||
type == OBJECT_MOBILErc || type == OBJECT_MOBILErc ||
type == OBJECT_MOBILErr || type == OBJECT_MOBILErr ||

View File

@ -53,12 +53,6 @@ class CLightManager;
} }
enum PhysicsType
{
TYPE_ROLLING = 1,
TYPE_FLYING = 2,
};
enum PhysicsMode enum PhysicsMode
{ {
MO_ADVACCEL = 0, MO_ADVACCEL = 0,
@ -112,9 +106,6 @@ public:
void SetMotion(CMotion* motion); void SetMotion(CMotion* motion);
void SetType(PhysicsType type);
PhysicsType GetType();
bool Write(CLevelParserLine* line); bool Write(CLevelParserLine* line);
bool Read(CLevelParserLine* line); bool Read(CLevelParserLine* line);
@ -219,7 +210,6 @@ protected:
COldObject* m_object; COldObject* m_object;
CMotion* m_motion; CMotion* m_motion;
PhysicsType m_type; // TYPE_*
float m_gravity; // force of gravity float m_gravity; // force of gravity
float m_time; // absolute time float m_time; // absolute time
Math::Vector m_motorSpeed; // motor speed (-1..1) Math::Vector m_motorSpeed; // motor speed (-1..1)