diff --git a/src/kart.cpp b/src/kart.cpp index 386646f9c..0b6e646f1 100644 --- a/src/kart.cpp +++ b/src/kart.cpp @@ -309,7 +309,7 @@ Kart::~Kart() * * Returns true if the kart is 'resting', i.e. (nearly) not moving. */ -bool Kart::isInRest() +bool Kart::isInRest() const { return fabs(m_body->getLinearVelocity ().z())<0.2; } // isInRest @@ -599,6 +599,13 @@ void Kart::update (float dt) sgCopyVec2 ( m_last_track_coords, m_curr_track_coords ); Moveable::update(dt); + + // Check if a kart is (nearly) upside down and not moving much --> automatic rescue + if((fabs(m_curr_pos.hpr[2])>60 && getSpeed()<3.0f) ) + { + forceRescue(); + } + btTransform trans=getTrans(); TerrainInfo::update(trans.getOrigin()); if (getHoT()==Track::NOHIT || diff --git a/src/kart.hpp b/src/kart.hpp index 2e2d6de52..5a1b82bd7 100644 --- a/src/kart.hpp +++ b/src/kart.hpp @@ -127,9 +127,9 @@ private: bool m_finished_race; float m_speed; + bool m_rescue; protected: - int m_rescue; float m_rescue_pitch, m_rescue_roll; const KartProperties *m_kart_properties; @@ -222,13 +222,14 @@ public: float getWheelieAngle () const {return m_wheelie_angle; } btRaycastVehicle *getVehicle () const {return m_vehicle; } void updateBulletPhysics(float dt); - void draw (); - bool isInRest (); + void draw (); + bool isInRest () const; //have to use this instead of moveable getVelocity to get velocity for bullet rigid body - float getSpeed () const {return m_speed; } - float handleWheelie(float dt); + float getSpeed () const {return m_speed; } + float handleWheelie (float dt); float getActualWheelForce(); - bool isOnGround (); + bool isOnGround (); + bool isRescue () const {return m_rescue;} void adjustSpeedWeight(float f); void forceRescue (); void handleExplosion (const sgVec3& pos, bool direct_hit); diff --git a/src/player_kart.cpp b/src/player_kart.cpp index 9b87cfc64..c20b36acc 100644 --- a/src/player_kart.cpp +++ b/src/player_kart.cpp @@ -139,7 +139,7 @@ void PlayerKart::update(float dt) return; } - if ( m_controls.fire && !m_rescue) + if ( m_controls.fire && !isRescue()) { if (m_collectable.getType()==COLLECT_NOTHING) sound_manager->playSfx(SOUND_BEEP); // use() needs to be called even if there currently is no collecteable diff --git a/src/robots/default_robot.cpp b/src/robots/default_robot.cpp index 3dc8f5425..2cff6087c 100755 --- a/src/robots/default_robot.cpp +++ b/src/robots/default_robot.cpp @@ -288,7 +288,7 @@ void DefaultRobot::handle_items( const float DELTA, const int STEPS ) { m_controls.fire = false; - if( m_rescue ) + if(isRescue() ) { return; } @@ -474,33 +474,26 @@ void DefaultRobot::handle_rescue(const float DELTA) //Reaction to being stuck if( m_crash_time > 3.0f ) { - m_rescue = true; + forceRescue(); m_crash_time = 0.0f; } -#if 0 - //FIXME: this is from the kart.cpp; since we already have a way to rescue, - //I don't know if this is needed. // check if kart is stuck - if(!isPlayerKart() && getVehicle()->getRigidBody()->getLinearVelocity().length()<2.0f - && !m_rescue && world->getPhase() != World::START_PHASE) + if(getVehicle()->getRigidBody()->getLinearVelocity().length()<2.0f && + !isRescue() && world->getPhase() != World::START_PHASE ) { - m_time_since_stuck += dt; + m_time_since_stuck += DELTA; + if(m_time_since_stuck > 2.0f) + { + forceRescue(); + m_time_since_stuck=0.0f; + } // m_time_since_stuck > 2.0f } else { m_time_since_stuck = 0.0f; } - - // Check if a kart needs to be rescued. - if((fabs(m_curr_pos.hpr[2])>60 && - sgLengthVec3(m_velocity.xyz)<3.0f) || m_time_since_stuck > 2.0f) - { - m_rescue=true; - m_time_since_stuck=0.0f; - } -#endif } //----------------------------------------------------------------------------- diff --git a/src/robots/default_robot.hpp b/src/robots/default_robot.hpp index 17f14cc44..6053f6643 100755 --- a/src/robots/default_robot.hpp +++ b/src/robots/default_robot.hpp @@ -93,9 +93,7 @@ private: float m_curve_target_speed; float m_curve_angle; -#if 0 float m_time_since_stuck; -#endif int m_start_kart_crash_direction; //-1 = left, 1 = right, 0 = no crash.