diff --git a/src/object/motion/motionant.cpp b/src/object/motion/motionant.cpp index f96da8dc..ab1e2398 100644 --- a/src/object/motion/motionant.cpp +++ b/src/object/motion/motionant.cpp @@ -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(m_object)->GetDying() == DeathType::Burning ) // burning? { - if ( m_object->GetFixed() ) + if ( dynamic_cast(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(m_object)->SetFixed(false); // moving again } } else diff --git a/src/object/motion/motionspider.cpp b/src/object/motion/motionspider.cpp index 8bad1264..4c7c1b4c 100644 --- a/src/object/motion/motionspider.cpp +++ b/src/object/motion/motionspider.cpp @@ -27,6 +27,8 @@ #include "object/old_object.h" +#include "object/subclass/base_alien.h" + #include "physics/physics.h" #include @@ -362,7 +364,7 @@ bool CMotionSpider::EventFrame(const Event &event) assert(m_object->Implements(ObjectInterfaceType::Destroyable)); if (dynamic_cast(m_object)->GetDying() == DeathType::Burning ) // burning? { - if ( m_object->GetFixed() ) + if ( dynamic_cast(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(m_object)->SetFixed(false); // moving again } } else diff --git a/src/object/old_object.cpp b/src/object/old_object.cpp index 9f92ce3b..6081c329 100644 --- a/src/object/old_object.cpp +++ b/src/object/old_object.cpp @@ -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(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(GetFixed())); - if ( !GetCollisions() ) line->AddParam("clip", MakeUnique(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(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. diff --git a/src/object/old_object.h b/src/object/old_object.h index 9787c694..0706fe92 100644 --- a/src/object/old_object.h +++ b/src/object/old_object.h @@ -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; diff --git a/src/object/old_object_interface.cpp b/src/object/old_object_interface.cpp index e65818f7..4d5bb13d 100644 --- a/src/object/old_object_interface.cpp +++ b/src/object/old_object_interface.cpp @@ -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!"); diff --git a/src/object/old_object_interface.h b/src/object/old_object_interface.h index a372e8ea..5a3e72ca 100644 --- a/src/object/old_object_interface.h +++ b/src/object/old_object_interface.h @@ -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(); diff --git a/src/object/subclass/base_alien.cpp b/src/object/subclass/base_alien.cpp index 7efc404c..d1f2f156 100644 --- a/src/object/subclass/base_alien.cpp +++ b/src/object/subclass/base_alien.cpp @@ -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::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(GetFixed())); +} diff --git a/src/object/subclass/base_alien.h b/src/object/subclass/base_alien.h index 39f9bc85..4e0c8e27 100644 --- a/src/object/subclass/base_alien.h +++ b/src/object/subclass/base_alien.h @@ -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; }; diff --git a/src/object/task/taskadvance.cpp b/src/object/task/taskadvance.cpp index 201fffe5..a066d8f3 100644 --- a/src/object/task/taskadvance.cpp +++ b/src/object/task/taskadvance.cpp @@ -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(m_object); + if ( alien != nullptr && alien->GetFixed() ) { m_physics->SetMotorSpeedX(0.0f); // stops the advance m_physics->SetMotorSpeedZ(0.0f); // stops the rotation diff --git a/src/object/task/taskfireant.cpp b/src/object/task/taskfireant.cpp index 483649b9..b95b22d3 100644 --- a/src/object/task/taskfireant.cpp +++ b/src/object/task/taskfireant.cpp @@ -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(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(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(m_object)->GetFixed() ) return ERR_STOP; // insect on its back? if ( m_phase == TFA_TURN ) // rotation ? { diff --git a/src/object/task/taskgoto.cpp b/src/object/task/taskgoto.cpp index c47a97d2..a4df61fd 100644 --- a/src/object/task/taskgoto.cpp +++ b/src/object/task/taskgoto.cpp @@ -34,6 +34,8 @@ #include "object/interface/transportable_object.h" +#include "object/subclass/base_alien.h" + #include "physics/physics.h" #include @@ -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(m_object); + if ( alien != nullptr && alien->GetFixed() ) { m_physics->SetMotorSpeedX(0.0f); // stops the advance m_physics->SetMotorSpeedZ(0.0f); // stops the rotation diff --git a/src/object/task/taskspiderexplo.cpp b/src/object/task/taskspiderexplo.cpp index 87966b0a..28eb3454 100644 --- a/src/object/task/taskspiderexplo.cpp +++ b/src/object/task/taskspiderexplo.cpp @@ -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(m_object)->GetFixed() ) { m_bError = true; return true; diff --git a/src/object/task/taskterraform.cpp b/src/object/task/taskterraform.cpp index e4c53979..753c2f0d 100644 --- a/src/object/task/taskterraform.cpp +++ b/src/object/task/taskterraform.cpp @@ -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(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(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(pObj)->SetFixed(true); // not moving } } } diff --git a/src/object/task/taskturn.cpp b/src/object/task/taskturn.cpp index 53507015..89284a45 100644 --- a/src/object/task/taskturn.cpp +++ b/src/object/task/taskturn.cpp @@ -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(m_object); + if ( alien != nullptr && alien->GetFixed() ) { m_physics->SetMotorSpeedX(0.0f); // stops the advance m_physics->SetMotorSpeedZ(0.0f); // stops the rotation diff --git a/src/physics/physics.cpp b/src/physics/physics.cpp index 06e93a03..4a678a91 100644 --- a/src/physics/physics.cpp +++ b/src/physics/physics.cpp @@ -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(m_object)->GetDying() == DeathType::Burning || - m_object->GetFixed() ) + dynamic_cast(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(m_object)->GetDying() == DeathType::Burning || - m_object->GetFixed() ) + dynamic_cast(m_object)->GetFixed() ) { if ( m_lastSoundInsect <= 0.0f ) { diff --git a/src/script/scriptfunc.cpp b/src/script/scriptfunc.cpp index 3da5f645..e04c63ba 100644 --- a/src/script/scriptfunc.cpp +++ b/src/script/scriptfunc.cpp @@ -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(pThis) != nullptr && dynamic_cast(pThis)->GetFixed() ) // ant on the back? { speed = 0.0f; turn = 0.0f;