Moved SetFixed/GetFixed to CBaseAlien

master
krzys-h 2015-08-17 13:19:21 +02:00
parent 304b0b20d8
commit 63bee182d2
16 changed files with 102 additions and 76 deletions

View File

@ -27,6 +27,8 @@
#include "object/old_object.h"
#include "object/subclass/base_alien.h"
#include "physics/physics.h"
@ -427,7 +429,7 @@ bool CMotionAnt::EventFrame(const Event &event)
assert(m_object->Implements(ObjectInterfaceType::Destroyable));
if ( dynamic_cast<CDestroyableObject*>(m_object)->GetDying() == DeathType::Burning ) // burning?
{
if ( m_object->GetFixed() )
if ( dynamic_cast<CBaseAlien*>(m_object)->GetFixed() )
{
m_actionType = MAS_BURN;
}
@ -722,7 +724,7 @@ bool CMotionAnt::EventFrame(const Event &event)
if ( m_progress >= 1.0f )
{
SetAction(-1);
m_object->SetFixed(false); // moving again
dynamic_cast<CBaseAlien*>(m_object)->SetFixed(false); // moving again
}
}
else

View File

@ -27,6 +27,8 @@
#include "object/old_object.h"
#include "object/subclass/base_alien.h"
#include "physics/physics.h"
#include <stdio.h>
@ -362,7 +364,7 @@ bool CMotionSpider::EventFrame(const Event &event)
assert(m_object->Implements(ObjectInterfaceType::Destroyable));
if (dynamic_cast<CDestroyableObject*>(m_object)->GetDying() == DeathType::Burning ) // burning?
{
if ( m_object->GetFixed() )
if ( dynamic_cast<CBaseAlien*>(m_object)->GetFixed() )
{
m_actionType = MSS_BURN;
}
@ -646,7 +648,7 @@ bool CMotionSpider::EventFrame(const Event &event)
if ( m_progress >= 1.0f )
{
SetAction(-1);
m_object->SetFixed(false); // moving again
dynamic_cast<CBaseAlien*>(m_object)->SetFixed(false); // moving again
}
}
else

View File

@ -51,6 +51,7 @@
#include "object/motion/motion.h"
#include "object/motion/motionvehicle.h"
#include "object/subclass/base_alien.h"
#include "object/subclass/exchange_post.h"
#include "physics/physics.h"
@ -134,7 +135,6 @@ COldObject::COldObject(int id)
m_bTrainer = false;
m_bToy = false;
m_bManual = false;
m_bFixed = false;
m_aTime = 0.0f;
m_shotTime = 0.0f;
m_bVirusMode = false;
@ -961,11 +961,6 @@ void COldObject::Write(CLevelParserLine* line)
if ( !GetSelectable() )
line->AddParam("selectable", MakeUnique<CLevelParserParam>(GetSelectable()));
// TODO: doesn't seem to be used
// But it is, this is used by aliens after Thumper ~krzys_h
if ( GetFixed() )
line->AddParam("fixed", MakeUnique<CLevelParserParam>(GetFixed()));
if ( !GetCollisions() )
line->AddParam("clip", MakeUnique<CLevelParserParam>(GetCollisions()));
@ -1139,7 +1134,6 @@ void COldObject::Read(CLevelParserLine* line)
// Everthing below is for use only by saved scenes
if (line->GetParam("energy")->IsDefined())
SetEnergyLevel(line->GetParam("energy")->AsFloat());
SetFixed(line->GetParam("fixed")->AsBool(false));
SetLock(line->GetParam("lock")->AsBool(false));
SetGunGoalV(line->GetParam("aimV")->AsFloat(0.0f));
SetGunGoalH(line->GetParam("aimH")->AsFloat(0.0f));
@ -2048,20 +2042,25 @@ bool COldObject::EventProcess(const Event &event)
{
axeZ = -1.0f; // tomb
if ( !GetFixed() &&
(m_type == OBJECT_ANT ||
if ( (m_type == OBJECT_ANT ||
m_type == OBJECT_SPIDER ||
m_type == OBJECT_WORM ) )
{
axeY = 2.0f; // zigzag disorganized fast
if ( m_type == OBJECT_WORM ) axeY = 5.0f;
axeX = 0.5f+sinf(m_time* 1.0f)*0.5f+
sinf(m_time* 6.0f)*2.0f+
sinf(m_time*21.0f)*0.2f;
float factor = 1.0f-m_burnTime/15.0f; // slow motion
if ( factor < 0.0f ) factor = 0.0f;
axeY *= factor;
axeX *= factor;
// TODO: Move to CBaseAlien?
CBaseAlien* alien = dynamic_cast<CBaseAlien*>(this);
assert(alien != nullptr);
if (!alien->GetFixed())
{
axeY = 2.0f; // zigzag disorganized fast
if ( m_type == OBJECT_WORM ) axeY = 5.0f;
axeX = 0.5f+sinf(m_time* 1.0f)*0.5f+
sinf(m_time* 6.0f)*2.0f+
sinf(m_time*21.0f)*0.2f;
float factor = 1.0f-m_burnTime/15.0f; // slow motion
if ( factor < 0.0f ) factor = 0.0f;
axeY *= factor;
axeX *= factor;
}
}
}
m_physics->SetMotorSpeedX(axeY); // move forward/move back
@ -2537,18 +2536,6 @@ void COldObject::SetTransparency(float value)
}
}
// Indicates whether an object is stationary (ant on the back).
void COldObject::SetFixed(bool bFixed)
{
m_bFixed = bFixed;
}
bool COldObject::GetFixed()
{
return m_bFixed;
}
// Pushes an object.

View File

@ -210,9 +210,6 @@ public:
void SetTransparency(float value) override;
void SetFixed(bool bFixed) override;
bool GetFixed() override;
Math::Sphere GetJostlingSphere() const override;
bool JostleObject(float force) override;
@ -360,7 +357,6 @@ protected:
bool m_bTrainer; // drive vehicle (without remote)
bool m_bToy; // toy key
bool m_bManual; // manual control (Scribbler)
bool m_bFixed;
float m_gunGoalV;
float m_gunGoalH;
Gfx::CameraType m_cameraType;

View File

@ -95,17 +95,6 @@ Character* COldObjectInterface::GetCharacter()
}
void COldObjectInterface::SetFixed(bool bFixed)
{
throw std::logic_error("SetFixed: not implemented!");
}
bool COldObjectInterface::GetFixed()
{
throw std::logic_error("GetFixed: not implemented!");
}
void COldObjectInterface::SetVirusMode(bool bEnable)
{
throw std::logic_error("SetVirusMode: not implemented!");

View File

@ -81,10 +81,6 @@ public:
virtual void FlatParent();
// This goes to CBaseAlien or something like that
virtual void SetFixed(bool bFixed);
virtual bool GetFixed();
// Not sure. Maybe a separate interface, or maybe CControllableObject (buildings can have viruses too)
virtual void SetVirusMode(bool bEnable);
virtual bool GetVirusMode();

View File

@ -21,6 +21,9 @@
#include "common/make_unique.h"
#include "level/parser/parserline.h"
#include "level/parser/parserparam.h"
#include "graphics/engine/oldmodelmanager.h"
#include "object/object_create_params.h"
@ -35,7 +38,8 @@
CBaseAlien::CBaseAlien(int id, ObjectType type)
: CBaseVehicle(id, type)
: CBaseVehicle(id, type),
m_fixed(false)
{}
CBaseAlien::~CBaseAlien()
@ -85,3 +89,28 @@ std::unique_ptr<CBaseAlien> CBaseAlien::Create(
return std::move(obj);
}
void CBaseAlien::SetFixed(bool fixed)
{
m_fixed = fixed;
}
bool CBaseAlien::GetFixed()
{
return m_fixed;
}
void CBaseAlien::Read(CLevelParserLine* line)
{
COldObject::Read(line);
SetFixed(line->GetParam("fixed")->AsBool(false));
}
void CBaseAlien::Write(CLevelParserLine* line)
{
COldObject::Write(line);
if (GetFixed())
line->AddParam("fixed", MakeUnique<CLevelParserParam>(GetFixed()));
}

View File

@ -44,4 +44,17 @@ public:
const ObjectCreateParams& params,
Gfx::COldModelManager* modelManager,
Gfx::CEngine* engine);
public:
//! Management of "temporarirly stationary" mode (alien on the back)
//@{
void SetFixed(bool fixed);
bool GetFixed();
//@}
void Write(CLevelParserLine* line) override;
void Read(CLevelParserLine* line) override;
protected:
bool m_fixed;
};

View File

@ -25,9 +25,10 @@
#include "math/geometry.h"
#include "object/object.h"
#include "object/old_object.h"
#include "object/subclass/base_alien.h"
#include "physics/physics.h"
@ -56,7 +57,8 @@ bool CTaskAdvance::EventProcess(const Event &event)
m_fixTime += event.rTime;
// Momentarily stationary object (ant on the back)?
if ( m_object->GetFixed() )
CBaseAlien* alien = dynamic_cast<CBaseAlien*>(m_object);
if ( alien != nullptr && alien->GetFixed() )
{
m_physics->SetMotorSpeedX(0.0f); // stops the advance
m_physics->SetMotorSpeedZ(0.0f); // stops the rotation

View File

@ -28,6 +28,8 @@
#include "object/motion/motionant.h"
#include "object/subclass/base_alien.h"
#include "physics/physics.h"
@ -58,7 +60,7 @@ bool CTaskFireAnt::EventProcess(const Event &event)
if ( event.type != EVENT_FRAME ) return true;
if ( m_bError ) return false;
if ( m_object->GetFixed() ) // insect on its back?
if ( dynamic_cast<CBaseAlien*>(m_object)->GetFixed() ) // insect on its back?
{
m_bError = true;
return false;
@ -98,7 +100,7 @@ Error CTaskFireAnt::Start(Math::Vector impact)
if ( type != OBJECT_ANT ) return ERR_WRONG_BOT;
// Insect on its back?
if ( m_object->GetFixed() ) return ERR_WRONG_BOT;
if ( dynamic_cast<CBaseAlien*>(m_object)->GetFixed() ) return ERR_WRONG_BOT;
m_physics->SetMotorSpeed(Math::Vector(0.0f, 0.0f, 0.0f));
@ -128,7 +130,7 @@ Error CTaskFireAnt::IsEnded()
if ( m_engine->GetPause() ) return ERR_CONTINUE;
if ( m_bError ) return ERR_STOP;
if ( m_object->GetFixed() ) return ERR_STOP; // insect on its back?
if ( dynamic_cast<CBaseAlien*>(m_object)->GetFixed() ) return ERR_STOP; // insect on its back?
if ( m_phase == TFA_TURN ) // rotation ?
{

View File

@ -34,6 +34,8 @@
#include "object/interface/transportable_object.h"
#include "object/subclass/base_alien.h"
#include "physics/physics.h"
#include <string.h>
@ -79,7 +81,8 @@ bool CTaskGoto::EventProcess(const Event &event)
if ( event.type != EVENT_FRAME ) return true;
// Momentarily stationary object (ant on the back)?
if ( m_object->GetFixed() )
CBaseAlien* alien = dynamic_cast<CBaseAlien*>(m_object);
if ( alien != nullptr && alien->GetFixed() )
{
m_physics->SetMotorSpeedX(0.0f); // stops the advance
m_physics->SetMotorSpeedZ(0.0f); // stops the rotation

View File

@ -27,6 +27,8 @@
#include "object/motion/motionspider.h"
#include "object/subclass/base_alien.h"
#include "physics/physics.h"
@ -55,7 +57,7 @@ bool CTaskSpiderExplo::EventProcess(const Event &event)
if ( event.type != EVENT_FRAME ) return true;
// Momentarily stationary object (ant on the back)?
if ( m_object->GetFixed() )
if ( dynamic_cast<CBaseAlien*>(m_object)->GetFixed() )
{
m_bError = true;
return true;

View File

@ -35,6 +35,8 @@
#include "object/motion/motionant.h"
#include "object/motion/motionspider.h"
#include "object/subclass/base_alien.h"
#include "physics/physics.h"
@ -377,21 +379,16 @@ bool CTaskTerraform::Terraform()
dist = Math::Distance(m_terraPos, pObj->GetPosition());
if ( dist > ACTION_RADIUS ) continue;
if ( type == OBJECT_ANT )
if ( type == OBJECT_ANT || type == OBJECT_SPIDER )
{
assert(pObj->Implements(ObjectInterfaceType::TaskExecutor));
dynamic_cast<CTaskExecutorObject*>(pObj)->StopForegroundTask();
motion->SetAction(MAS_BACK1, 0.8f+Math::Rand()*0.3f);
pObj->SetFixed(true); // not moving
}
if ( type == OBJECT_SPIDER )
{
assert(pObj->Implements(ObjectInterfaceType::TaskExecutor));
dynamic_cast<CTaskExecutorObject*>(pObj)->StopForegroundTask();
motion->SetAction(MSS_BACK1, 0.8f+Math::Rand()*0.3f);
pObj->SetFixed(true); // not moving
int actionType = -1;
if (type == OBJECT_ANT) actionType = MAS_BACK1;
if (type == OBJECT_SPIDER) actionType = MSS_BACK1;
motion->SetAction(actionType, 0.8f+Math::Rand()*0.3f);
dynamic_cast<CBaseAlien*>(pObj)->SetFixed(true); // not moving
}
}
}

View File

@ -26,6 +26,8 @@
#include "object/old_object.h"
#include "object/subclass/base_alien.h"
#include "physics/physics.h"
@ -50,7 +52,8 @@ bool CTaskTurn::EventProcess(const Event &event)
if ( event.type != EVENT_FRAME ) return true;
// Momentarily stationary object (ant on the back)?
if ( m_object->GetFixed() )
CBaseAlien* alien = dynamic_cast<CBaseAlien*>(m_object);
if ( alien != nullptr && alien->GetFixed() )
{
m_physics->SetMotorSpeedX(0.0f); // stops the advance
m_physics->SetMotorSpeedZ(0.0f); // stops the rotation

View File

@ -52,6 +52,8 @@
#include "object/motion/motionhuman.h"
#include "object/motion/motionvehicle.h"
#include "object/subclass/base_alien.h"
#include "object/task/task.h"
@ -1605,7 +1607,7 @@ void CPhysics::SoundMotor(float rTime)
{
assert(m_object->Implements(ObjectInterfaceType::Destroyable));
if ( dynamic_cast<CDestroyableObject*>(m_object)->GetDying() == DeathType::Burning ||
m_object->GetFixed() )
dynamic_cast<CBaseAlien*>(m_object)->GetFixed() )
{
if ( m_lastSoundInsect <= 0.0f )
{
@ -1669,7 +1671,7 @@ void CPhysics::SoundMotor(float rTime)
{
assert(m_object->Implements(ObjectInterfaceType::Destroyable));
if ( dynamic_cast<CDestroyableObject*>(m_object)->GetDying() == DeathType::Burning ||
m_object->GetFixed() )
dynamic_cast<CBaseAlien*>(m_object)->GetFixed() )
{
if ( m_lastSoundInsect <= 0.0f )
{

View File

@ -50,6 +50,7 @@
#include "object/interface/task_executor_object.h"
#include "object/interface/trace_drawing_object.h"
#include "object/subclass/base_alien.h"
#include "object/subclass/exchange_post.h"
#include "object/task/taskinfo.h"
@ -2695,7 +2696,7 @@ bool CScriptFunctions::rMotor(CBotVar* var, CBotVar* result, int& exception, voi
if ( turn < -1.0f ) turn = -1.0f;
if ( turn > 1.0f ) turn = 1.0f;
if ( pThis->GetFixed() ) // ant on the back?
if ( dynamic_cast<CBaseAlien*>(pThis) != nullptr && dynamic_cast<CBaseAlien*>(pThis)->GetFixed() ) // ant on the back?
{
speed = 0.0f;
turn = 0.0f;