Fixed automatic rescue:
1) called when any kart is not upside down and slowed down 2) called for AI when it's not making progress (the old method of using m_collided did not work in at least one case I have seen). git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1395 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
bf4ee7a970
commit
4c4eee4c4d
@ -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 ||
|
||||
|
13
src/kart.hpp
13
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);
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -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.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user