Back to index

supertuxkart  0.5+dfsg1
kart.hpp
Go to the documentation of this file.
00001 //  $Id: kart.hpp 2111 2008-05-31 07:04:30Z cosmosninja $
00002 //
00003 //  SuperTuxKart - a fun racing game with go-kart
00004 //  Copyright (C) 2004-2005 Steve Baker <sjbaker1@airmail.net>
00005 //  Copyright (C) 2006 SuperTuxKart-Team, Joerg Henrichs, Steve Baker
00006 //
00007 //  This program is free software; you can redistribute it and/or
00008 //  modify it under the terms of the GNU General Public License
00009 //  as published by the Free Software Foundation; either version 2
00010 //  of the License, or (at your option) any later version.
00011 //
00012 //  This program is distributed in the hope that it will be useful,
00013 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 //  GNU General Public License for more details.
00016 //
00017 //  You should have received a copy of the GNU General Public License
00018 //  along with this program; if not, write to the Free Software
00019 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00020 
00021 #ifndef HEADER_KART_H
00022 #define HEADER_KART_H
00023 
00024 #include <plib/sg.h>
00025 #include "btBulletDynamicsCommon.h"
00026 
00027 #include "moveable.hpp"
00028 #include "kart_properties.hpp"
00029 #include "attachment.hpp"
00030 #include "collectable.hpp"
00031 #include "terrain_info.hpp"
00032 
00033 struct KartControl
00034 {
00035     float lr;
00036     float accel;
00037     bool  brake;
00038     bool  wheelie;
00039     bool  jump;
00040     bool  rescue;
00041     bool  fire;
00042 
00043     KartControl() : lr(0.0f), accel(0.0f), brake(false),
00044     wheelie(false), jump(false),  rescue(false), fire(false){}
00045 };
00046 
00047 class SkidMark;
00048 class Herring;
00049 class Smoke;
00050 
00051 class Kart : public TerrainInfo, public Moveable
00052 {
00053 protected:
00054     bool         m_on_road;            // true if the kart is on top of the
00055                                        // road path drawn by the drivelines
00056     Attachment   m_attachment;
00057     Collectable  m_collectable;
00058 
00059     int          m_grid_position;
00060     int          m_race_position;      // current race position (1-numKarts)
00061     int          m_initial_position;   // initial position of kart
00062     KartControl  m_controls;           // The position of the karts controls
00063     int          m_track_sector;       // index in driveline, special values
00064                                        // e.g. UNKNOWN_SECTOR can be negative!
00065     sgVec2       m_last_track_coords;
00066     sgVec3       m_curr_track_coords;
00067     float        m_max_speed;          // maximum speed of the kart, computed from
00068     float        m_max_speed_reverse_ratio;
00069     float        m_wheelie_angle;
00070     float        m_zipper_time_left;   // zipper time left
00071     float        m_lap_start_time;     // Time at start of a new lap
00072     char         m_fastest_lap_message[255];
00073 
00074     int          m_shortcut_sector;    // segment on which the shortcut was started
00075 
00076     // physics parameters, storing it saves time
00077     btRaycastVehicle::btVehicleTuning  *m_tuning;
00078     btCompoundShape                    m_kart_chassis;
00079     btVehicleRaycaster                 *m_vehicle_raycaster;
00080     btRaycastVehicle                   *m_vehicle;
00081     btUprightConstraint                *m_uprightConstraint;
00082 
00083 private:
00084     int                 m_num_herrings_gobbled;
00085     ssgSimpleState*     m_smokepuff;
00086     // don't delete the following 2 vars (they're kids in the hirarchy)
00087     Smoke              *m_smoke_system;
00088     ssgTransform*       m_exhaust_pipe;
00089 
00090     float               m_wheel_rotation;
00091     ssgTransform*       m_wheel_front_l;
00092     ssgTransform*       m_wheel_front_r;
00093     ssgTransform*       m_wheel_rear_l;
00094     ssgTransform*       m_wheel_rear_r;
00095 
00096     SkidMark*           m_skidmark_left;
00097     SkidMark*           m_skidmark_right;
00098 
00099     int                 m_race_lap;             // number of finished(!) laps
00100     float               m_time_at_last_lap;       // time at finishing last lap
00101     float               m_finish_time;
00102     bool                m_finished_race;
00103 
00104     float               m_speed;
00105     bool                m_rescue;
00106     bool                m_eliminated;
00107 
00108 protected:
00109     float               m_rescue_pitch, m_rescue_roll;
00110     const KartProperties *m_kart_properties;
00111 
00114     void  load_wheels          (ssgBranch* obj);
00115 
00116 public:
00117                    Kart(const std::string& kart_name, int position_, 
00118                         sgCoord init_pos);
00119     virtual       ~Kart();
00120     void           loadData();
00121     void           placeModel ();
00122     const KartProperties* 
00123                    getKartProperties   () const      { return m_kart_properties; }
00124     void           setKartProperties   (const KartProperties *kp)
00125                                           { m_kart_properties=kp;                }
00126     void           attach              (attachmentType attachment_, float time)
00127                                           { m_attachment.set(attachment_, time); }
00128     void           setCollectable      (CollectableType t, int n)
00129                                           { m_collectable.set(t, n);             }
00130     virtual void   setPosition         (int p)    
00131                                           { m_race_position = p;                 }
00132     int            getSector           () const { return m_track_sector;         }
00133     float          getDistanceDownTrack() const { return m_curr_track_coords[1]; }
00134     float          getDistanceToCenter () const { return m_curr_track_coords[0]; }
00135     Attachment    *getAttachment       ()       { return &m_attachment;          }
00136     void           setAttachmentType   (attachmentType t, float time_left=0.0f,
00137                                         Kart*k=NULL)
00138                                           { m_attachment.set(t, time_left, k);   }
00139     Collectable   *getCollectable      ()       { return &m_collectable;         }
00140     int            getNumCollectables  () const { return  m_collectable.getNum();}
00141     int            getNumHerring       () const { return  m_num_herrings_gobbled;}
00142     int            getLap              () const { return  m_race_lap;            }
00143     int            getPosition         () const { return  m_race_position;       }
00144     int            getInitialPosition  () const { return  m_initial_position;    }
00145     void           setFinishingState(float time);
00146     float          getFinishTime       () const  { return m_finish_time;         }
00147     bool           raceIsFinished      () const  { return m_finished_race;       }
00148     void           endRescue           ();
00149     float          estimateFinishTime  ();
00150     void           processSkidMarks    ();
00151     void           getClosestKart      (float *cdist, int *closest);
00152     void           updatePhysics       (float dt);
00153 
00154     // Functions to access the current kart properties (which might get changed,
00155     // e.g. mass increase or air_friction increase depending on attachment etc.)
00156     // -------------------------------------------------------------------------
00157     const sgVec3*  getColor         () const {return m_kart_properties->getColor();}
00158     float          getMass          () const
00159     {
00160         return m_kart_properties->getMass()
00161                + m_attachment.WeightAdjust();
00162     }
00163     float          getMaxPower      () const {return m_kart_properties->getMaxPower();}
00164     float          getTimeFullSteer () const {return m_kart_properties->getTimeFullSteer();}
00165     float          getBrakeFactor   () const {return m_kart_properties->getBrakeFactor();}
00166     float          getWheelBase     () const {return m_kart_properties->getWheelBase();}
00167     float          getHeightCOG     () const {return m_kart_properties->getHeightCOG();}
00168     float          getFrictionSlip  () const {return m_kart_properties->getFrictionSlip();}
00169     float          getMaxSteerAngle () const {return m_kart_properties->getMaxSteerAngle();}
00170     float          getGravityCenterShift   () const
00171         {return m_kart_properties->getGravityCenterShift();                    }
00172     float          getWheelieMaxSpeedRatio () const
00173         {return m_kart_properties->getWheelieMaxSpeedRatio();                  }
00174     float          getWheelieMaxPitch  () const
00175         {return m_kart_properties->getWheelieMaxPitch();                       }
00176     float          getWheeliePitchRate () const
00177         {return m_kart_properties->getWheeliePitchRate();                      }
00178     float          getWheelieRestoreRate() const
00179         {return m_kart_properties->getWheelieRestoreRate();                    }
00180     float          getWheelieSpeedBoost() const
00181         {return m_kart_properties->getWheelieSpeedBoost();                     }
00182     float          getSteerAngle    () const
00183         {return m_controls.lr*m_kart_properties->getMaxSteerAngle();           }
00184     float          getSteerPercent  () const {return m_controls.lr;            }
00185     float          getMaxSpeed      () const {return m_max_speed;              }
00186     void           setTimeAtLap     (float t){m_time_at_last_lap=t;            }
00187     float          getTimeAtLap     () const {return m_time_at_last_lap;       }
00188     void           createPhysics    (ssgEntity *obj);
00189     float          getKartLength    () const {return m_kart_properties->getKartLength();}
00190     float          getKartHeight    () const {return m_kart_properties->getKartHeight();}
00191     float          getWheelieAngle  () const {return m_wheelie_angle;          }
00192     btRaycastVehicle *getVehicle    () const {return m_vehicle;                }
00193     btUprightConstraint *getUprightConstraint() const {return m_uprightConstraint;}
00194     void           updateBulletPhysics(float dt);
00195     void           draw             ();
00196     bool           isInRest         () const;
00197     //have to use this instead of moveable getVelocity to get velocity for bullet rigid body
00198     float          getSpeed         () const {return m_speed;                 }
00199     float          handleWheelie    (float dt);
00200     float          getActualWheelForce();
00201     bool           isOnGround       () const;
00202     bool           isEliminated     () const {return m_eliminated;}
00203     void           eliminate        ();
00204     bool           isRescue         () const {return m_rescue;}
00205     void           resetBrakes      ();
00206     void           adjustSpeedWeight(float f);
00207     void           forceRescue      (bool is_rescue=false);
00208     void           handleExplosion  (const btVector3& pos, bool direct_hit);
00209     const std::string& getName      () const {return m_kart_properties->getName();}
00210     virtual int    isPlayerKart     () const {return 0;                        }
00211     // addMessages gets called by world to add messages to the gui
00212     virtual void   addMessages      () {};
00213     virtual void   collectedHerring (Herring* herring);
00214     virtual void   reset            ();
00215     virtual void   handleZipper     ();
00216     virtual void   crashed          () {};
00217     virtual void   doLapCounting    ();
00218     virtual void   update           (float dt               );
00219 };
00220 
00221 class TrafficDriver : public Kart
00222 {
00223 public:
00224     TrafficDriver (const std::string& kart_name, sgVec3 _pos,
00225                    sgCoord init_pos)
00226         : Kart (kart_name, 0, init_pos )
00227     {
00228         sgCopyVec3 ( m_reset_pos.xyz, _pos ) ;
00229         reset () ;
00230     }
00231     virtual void doLapCounting        () ;
00232     virtual void doZipperProcessing   () ;
00233     virtual void update (float delta) ;
00234 } ;
00235 
00236 
00237 #endif
00238 
00239 /* EOF */
00240