From b41bd961258b16eb404967ac394d86cb1746fc85 Mon Sep 17 00:00:00 2001 From: hikerstk Date: Wed, 14 Jan 2009 23:36:30 +0000 Subject: [PATCH] 1) Fixed 'wild rotation' on sand (which was only a graphical effect, it didn't really happen in reality) 2) Applied Minibjorn's patch to allow more violent explosions. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@2922 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- data/stk_config.data | 3 +++ src/karts/kart.cpp | 27 +++++++++++++++++++++------ src/karts/kart.hpp | 8 +++++++- src/robots/default_robot.cpp | 8 ++++---- src/stk_config.cpp | 4 +++- src/stk_config.hpp | 4 ++++ 6 files changed, 42 insertions(+), 12 deletions(-) diff --git a/data/stk_config.data b/data/stk_config.data index 8524db1d9..001772cbc 100644 --- a/data/stk_config.data +++ b/data/stk_config.data @@ -20,6 +20,9 @@ (skid-fadeout-time 60) ;; Time till skidm marks fade out (slowdown-factor 10) ;; Engine reduction depending on terrain, ;; see kart for details. + (near-ground 2) ;; Distance above ground when the upright + ;; constraint will be disabled to allow + ;; more violent explosions. (delay-finish-time 10) ;; delay till race results are displayed. (music-credit-time 10) ;; time for which the music credits ;; are displayed. diff --git a/src/karts/kart.cpp b/src/karts/kart.cpp index a3451e1e1..29f640238 100644 --- a/src/karts/kart.cpp +++ b/src/karts/kart.cpp @@ -437,6 +437,19 @@ bool Kart::isOnGround() const m_vehicle->getWheelInfo(3).m_raycastInfo.m_isInContact; } // isOnGround //----------------------------------------------------------------------------- +/** The kart is near the ground, but not necesarily on it (small jumps). This + * is used to determine when to switch off the upright constraint, so that + * explosions can be more violent, while still +*/ + +bool Kart::isNearGround() const +{ + if(getHoT()==Track::NOHIT) + return false; + else + return ((getXYZ().getZ() - getHoT()) < stk_config->m_near_ground); +} // isNearGround +//----------------------------------------------------------------------------- void Kart::handleExplosion(const Vec3& pos, bool direct_hit) { if(direct_hit) @@ -473,6 +486,8 @@ void Kart::handleExplosion(const Vec3& pos, bool direct_hit) //----------------------------------------------------------------------------- void Kart::update(float dt) { + if(m_body->getAngularVelocity().getZ()>1.9f) + dt=1.0f*dt; // if its view is blocked by plunger, decrease remaining time if(m_view_blocked_by_plunger > 0) m_view_blocked_by_plunger -= dt; @@ -494,8 +509,8 @@ void Kart::update(float dt) m_controls.m_fire = false; } - // Only use the upright constraint if the kart is in the air! - if(isOnGround()) + // When really on air, free fly, when near ground, try to glide / adjust for landing + if(!isNearGround()) m_uprightConstraint->setLimit(M_PI); else m_uprightConstraint->setLimit(m_kart_properties->getUprightTolerance()); @@ -607,7 +622,7 @@ void Kart::update(float dt) { m_power_reduction = material->getSlowDown(); // Normal driving on terrain. Adjust for maximum terrain speed - float max_speed_here = material->getMaxSpeedFraction()*m_max_speed; + float max_speed_here = material->getMaxSpeedFraction()*getMaxSpeed(); // If the speed is too fast, reduce the maximum speed gradually. // The actual capping happens in updatePhysics if(max_speed_heregetLinearVelocity(); float current_speed = v.length(); float speed = std::min(current_speed+stk_config->m_zipper_speed_gain, - getMaxSpeed()); + getMaxSpeedOnTerrain()); // If the speed is too low, very minor components of the velocity vector // can become too big. E.g. each kart has a z component (to offset gravity // I assume, around 0.16) --> if the karts are (nearly) at standstill, @@ -773,7 +788,7 @@ void Kart::updatePhysics (float dt) { resetBrakes(); // going backward, apply reverse gear ratio (unless he goes too fast backwards) - if ( fabs(m_speed) < getMaxSpeed()*m_max_speed_reverse_ratio ) + if ( fabs(m_speed) < getMaxSpeedOnTerrain()*m_max_speed_reverse_ratio ) { // the backwards acceleration is artificially increased to allow // players to get "unstuck" quicker if they hit e.g. a wall @@ -858,7 +873,7 @@ void Kart::updatePhysics (float dt) m_speed *= -1.f; //cap at maximum velocity - const float max_speed = m_kart_properties->getMaxSpeed(); + const float max_speed = getMaxSpeedOnTerrain(); if ( m_speed > max_speed ) { const float velocity_ratio = max_speed/m_speed; diff --git a/src/karts/kart.hpp b/src/karts/kart.hpp index f00f1aa9f..4481d9d08 100644 --- a/src/karts/kart.hpp +++ b/src/karts/kart.hpp @@ -185,7 +185,12 @@ public: getControls () const {return m_controls; } /** Sets the kart controls. Used e.g. by replaying history. */ void setControls(const KartControl &c) { m_controls = c; } - float getMaxSpeed () const {return m_max_speed- + /** Returns the maximum speed of the kart independent of the + * terrain it is on. */ + float getMaxSpeed () const {return m_max_speed; } + /** Returns the maximum speed of the kart but includes the effect of + * the terrain it is on. */ + float getMaxSpeedOnTerrain() const {return m_max_speed- m_max_speed_reduction; } /** Returns the length of the kart. */ float getKartLength () const @@ -207,6 +212,7 @@ public: float handleNitro (float dt); float getActualWheelForce(); bool isOnGround () const; + bool isNearGround () const; bool isEliminated () const {return m_eliminated;} void eliminate (); bool isRescue () const {return m_rescue;} diff --git a/src/robots/default_robot.cpp b/src/robots/default_robot.cpp index b98eab953..a4c3e64a6 100755 --- a/src/robots/default_robot.cpp +++ b/src/robots/default_robot.cpp @@ -561,7 +561,7 @@ void DefaultRobot::handleAcceleration( const float DELTA ) if(hasViewBlockedByPlunger()) { - if(!(getSpeed() > getMaxSpeed() / 2)) + if(!(getSpeed() > getMaxSpeedOnTerrain() / 2)) m_controls.m_accel = 0.05f; else m_controls.m_accel = 0.0f; @@ -631,7 +631,7 @@ void DefaultRobot::handleNitroAndZipper() { m_controls.m_nitro = false; // If we are already very fast, save nitro. - if(getSpeed() > 0.95f*getMaxSpeed()) + if(getSpeed() > 0.95f*getMaxSpeedOnTerrain()) return; // Don't use nitro when the AI has a plunger in the face! if(hasViewBlockedByPlunger()) return; @@ -987,7 +987,7 @@ void DefaultRobot::reset() m_start_kart_crash_direction = 0; m_sector = Track::UNKNOWN_SECTOR; m_inner_curve = 0; - m_curve_target_speed = getMaxSpeed(); + m_curve_target_speed = getMaxSpeedOnTerrain(); m_curve_angle = 0.0; m_future_location[0] = 0.0; m_future_location[1] = 0.0; @@ -1182,5 +1182,5 @@ void DefaultRobot::findCurve() m_curve_angle = normalizeAngle(m_track->m_angle[i] - m_track->m_angle[m_track_sector]); m_inner_curve = m_curve_angle > 0.0 ? -1 : 1; - m_curve_target_speed = getMaxSpeed(); + m_curve_target_speed = getMaxSpeedOnTerrain(); } // findCurve diff --git a/src/stk_config.cpp b/src/stk_config.cpp index 196fc1a60..2afd07590 100644 --- a/src/stk_config.cpp +++ b/src/stk_config.cpp @@ -116,6 +116,7 @@ void STKConfig::load(const std::string &filename) CHECK_NEG(m_max_skidmarks, "max-skidmarks" ); CHECK_NEG(m_skid_fadeout_time, "skid-fadeout-time" ); CHECK_NEG(m_slowdown_factor, "slowdown-factor" ); + CHECK_NEG(m_near_ground, "near-ground" ); CHECK_NEG(m_delay_finish_time, "delay-finish-time" ); CHECK_NEG(m_music_credit_time, "music-credit-time" ); m_kart_properties.checkAllSet(filename); @@ -138,7 +139,7 @@ void STKConfig::init_defaults() m_shortcut_length = m_music_credit_time = m_delay_finish_time = m_skid_fadeout_time = m_slowdown_factor = m_offroad_tolerance = - m_final_camera_time = + m_final_camera_time = m_near_ground = UNDEFINED; m_max_karts = -100; m_grid_order = -100; @@ -202,6 +203,7 @@ void STKConfig::getAllData(const lisp::Lisp* lisp) lisp->get("max-skidmarks", m_max_skidmarks ); lisp->get("skid-fadeout-time", m_skid_fadeout_time ); lisp->get("slowdown-factor", m_slowdown_factor ); + lisp->get("near-ground", m_near_ground ); lisp->get("delay-finish-time", m_delay_finish_time ); lisp->get("music-credit-time", m_music_credit_time ); lisp->getVector("menu-background", m_menu_background ); diff --git a/src/stk_config.hpp b/src/stk_config.hpp index 85e067ed2..4ed11d062 100644 --- a/src/stk_config.hpp +++ b/src/stk_config.hpp @@ -75,6 +75,10 @@ public: int m_max_skidmarks; /**