Back to index

supertuxkart  0.5+dfsg1
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | Private Types | Private Member Functions | Private Attributes
DefaultRobot Class Reference

#include <default_robot.hpp>

Inheritance diagram for DefaultRobot:
Inheritance graph
[legend]
Collaboration diagram for DefaultRobot:
Collaboration graph
[legend]

List of all members.

Classes

class  CrashTypes

Public Member Functions

 DefaultRobot (const std::string &kart_name, int position, sgCoord init_pos)
void update (float delta)
void reset ()
int isPlayerKart () const
void loadData ()
void placeModel ()
const KartPropertiesgetKartProperties () const
void setKartProperties (const KartProperties *kp)
void attach (attachmentType attachment_, float time)
void setCollectable (CollectableType t, int n)
virtual void setPosition (int p)
int getSector () const
float getDistanceDownTrack () const
float getDistanceToCenter () const
AttachmentgetAttachment ()
void setAttachmentType (attachmentType t, float time_left=0.0f, Kart *k=NULL)
CollectablegetCollectable ()
int getNumCollectables () const
int getNumHerring () const
int getLap () const
int getPosition () const
int getInitialPosition () const
void setFinishingState (float time)
float getFinishTime () const
bool raceIsFinished () const
void endRescue ()
 Drops a kart which was rescued back on the track.
float estimateFinishTime ()
void processSkidMarks ()
void getClosestKart (float *cdist, int *closest)
void updatePhysics (float dt)
const sgVec3 * getColor () const
float getMass () const
float getMaxPower () const
float getTimeFullSteer () const
float getBrakeFactor () const
float getWheelBase () const
float getHeightCOG () const
float getFrictionSlip () const
float getMaxSteerAngle () const
float getGravityCenterShift () const
float getWheelieMaxSpeedRatio () const
float getWheelieMaxPitch () const
float getWheeliePitchRate () const
float getWheelieRestoreRate () const
float getWheelieSpeedBoost () const
float getSteerAngle () const
float getSteerPercent () const
float getMaxSpeed () const
void setTimeAtLap (float t)
float getTimeAtLap () const
void createPhysics (ssgEntity *obj)
float getKartLength () const
float getKartHeight () const
float getWheelieAngle () const
btRaycastVehiclegetVehicle () const
btUprightConstraintgetUprightConstraint () const
void updateBulletPhysics (float dt)
void draw ()
bool isInRest () const
 Returns true if the kart is 'resting'.
float getSpeed () const
float handleWheelie (float dt)
 Returned an additional engine power boost when doing a wheele.
float getActualWheelForce ()
bool isOnGround () const
 The kart is on ground if all 4 wheels touch the ground.
bool isEliminated () const
void eliminate ()
bool isRescue () const
void resetBrakes ()
 This function is called when the race starts.
void adjustSpeedWeight (float f)
 Modifies the physics parameter to simulate an attached anvil.
void forceRescue (bool is_rescue=false)
void handleExplosion (const btVector3 &pos, bool direct_hit)
const std::string & getName () const
virtual void addMessages ()
virtual void collectedHerring (Herring *herring)
virtual void handleZipper ()
virtual void crashed ()
virtual void doLapCounting ()
virtual void update (const btVector3 &pos)
float getHoT () const
const MaterialgetMaterial () const
const btVector3getNormal () const
float getTerrainPitch (float heading) const
 Returns the pitch of the terrain depending on the heading.
ssgTransform * getModelTransform ()
virtual const btVector3getVelocity () const
const btVector3getVelocityLC () const
virtual void setVelocity (const btVector3 &v)
sgCoord * getCoord ()
const sgCoord * getCoord () const
const btVector3 getPos () const
const sgVec4 * getNormalHOT () const
void setCoord (sgCoord *pos)
void WriteHistory (char *s, int kartNumber, int indx)
void ReadHistory (char *s, int kartNumber, int indx)
btRigidBodygetBody () const
void createBody (float mass, btTransform &trans, btCollisionShape *shape)
const btTransformgetTrans () const
void setTrans (btTransform &t)

Protected Member Functions

void load_wheels (ssgBranch *obj)
 Search the given branch of objects that match the wheel names and if so assign them to wheel_* variables.

Protected Attributes

bool m_on_road
Attachment m_attachment
Collectable m_collectable
int m_grid_position
int m_race_position
int m_initial_position
KartControl m_controls
int m_track_sector
sgVec2 m_last_track_coords
sgVec3 m_curr_track_coords
float m_max_speed
float m_max_speed_reverse_ratio
float m_wheelie_angle
float m_zipper_time_left
float m_lap_start_time
char m_fastest_lap_message [255]
int m_shortcut_sector
btRaycastVehicle::btVehicleTuningm_tuning
btCompoundShape m_kart_chassis
btVehicleRaycasterm_vehicle_raycaster
btRaycastVehiclem_vehicle
btUprightConstraintm_uprightConstraint
float m_rescue_pitch
float m_rescue_roll
const KartPropertiesm_kart_properties
UserPointer m_user_pointer
sgCoord m_reset_pos
sgCoord m_curr_pos
sgVec4 * m_normal_hot
Materialm_material_hot
ssgTransform * m_model_transform
ssgTransform * m_shadow
int m_collided
int m_crashed
sgVec3 m_surface_avoidance_vector
int m_first_time
sgCoord * m_history_velocity
sgCoord * m_history_position
btRigidBodym_body
btDefaultMotionStatem_motion_state
btTransform m_transform

Private Types

enum  FallbackTactic { FT_AVOID_TRACK_CRASH, FT_PARALLEL, FT_FAREST_POINT }
enum  ItemTactic { IT_TEN_SECONDS, IT_CALCULATE }

Private Member Functions

void handle_race_start ()
void handle_acceleration (const float DELTA)
void handle_steering ()
void handle_items (const float DELTA, const int STEPS)
void handle_rescue (const float DELTA)
void handle_braking ()
void handle_wheelie (const int STEPS)
float steer_to_angle (const size_t SECTOR, const float ANGLE)
float steer_to_point (const sgVec2 POINT)
bool do_wheelie (const int STEPS)
void check_crashes (const int STEPS, sgVec3 const pos)
void find_non_crashing_point (sgVec2 result)
 Find the sector that at the longest distance from the kart, that can be driven to without crashing with the track, then find towards which of the two edges of the track is closest to the next curve after wards, and return the position of that edge.
float normalize_angle (float angle)
int calc_steps ()
 calc_steps() divides the velocity vector by the lenght of the kart, and gets the number of steps to use for the sight line of the kart.
float angle_to_control (float angle) const
 Translates coordinates from an angle(in degrees) to values within the range of -1.0 to 1.0 to use the same format as the KartControl::lr variable.
float get_approx_radius (const int START, const int END) const
 Finds the approximate radius of a track's curve.
void find_curve ()
 Find_curve() gathers info about the closest sectors ahead: the curve angle, the direction of the next turn, and the optimal speed at which the curve can be travelled at it's widest angle.

Private Attributes

class DefaultRobot::CrashTypes m_crashes
float m_max_start_delay
int m_min_steps
bool m_wait_for_players
float m_max_handicap_accel
FallbackTactic m_fallback_tactic
bool m_use_wheelies
float m_wheelie_check_dist
ItemTactic m_item_tactic
float m_crash_time
float m_time_since_last_shot
int m_future_sector
sgVec2 m_future_location
float m_time_till_start
int m_inner_curve
float m_curve_target_speed
float m_curve_angle
float m_time_since_stuck
int m_start_kart_crash_direction
int m_sector

Detailed Description

Definition at line 24 of file default_robot.hpp.


Member Enumeration Documentation

Enumerator:
FT_AVOID_TRACK_CRASH 
FT_PARALLEL 
FT_FAREST_POINT 

Definition at line 27 of file default_robot.hpp.

    {
        FT_AVOID_TRACK_CRASH, //Only steer to avoid getting out of the road,
                              //otherwise, don't steer at all
        FT_PARALLEL,    //Stay parallel to the road
        FT_FAREST_POINT //Drive towards the farest non-crashing point that
                        //the kart can drive to in a straight line without
                        //crashing with the track.
    };
enum DefaultRobot::ItemTactic [private]
Enumerator:
IT_TEN_SECONDS 
IT_CALCULATE 

Definition at line 37 of file default_robot.hpp.

    {
        IT_TEN_SECONDS, //Fire after 10 seconds have passed, since the item
                        //was grabbed.
        IT_CALCULATE //Aim carefully, check for enough space for boosters,
                     //and that other conditions are meet before firing.
    };

Constructor & Destructor Documentation

DefaultRobot::DefaultRobot ( const std::string &  kart_name,
int  position,
sgCoord  init_pos 
)

Member Function Documentation

virtual void Kart::addMessages ( ) [inline, virtual, inherited]

Reimplemented in PlayerKart.

Definition at line 212 of file kart.hpp.

{};
void Kart::adjustSpeedWeight ( float  f) [inherited]

Modifies the physics parameter to simulate an attached anvil.

The velocity is multiplicated by f, and the mass of the kart is increased.

Definition at line 272 of file kart.cpp.

{
    m_body->setLinearVelocity(m_body->getLinearVelocity()*f);
    // getMass returns the mass increased by the attachment
    btVector3 inertia;
    float m=getMass();
    m_kart_chassis.calculateLocalInertia(m, inertia);
    m_body->setMassProps(m, inertia);
}   // adjustSpeedWeight

Here is the call graph for this function:

Here is the caller graph for this function:

float DefaultRobot::angle_to_control ( float  angle) const [private]

Translates coordinates from an angle(in degrees) to values within the range of -1.0 to 1.0 to use the same format as the KartControl::lr variable.

Definition at line 836 of file default_robot.cpp.

{
    angle *= 180.0f / ( getMaxSteerAngle() * M_PI ) ;

    if(angle > 1.0f) return 1.0f;
    else if(angle < -1.0f) return -1.0f;

    return angle;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Kart::attach ( attachmentType  attachment_,
float  time 
) [inline, inherited]

Definition at line 126 of file kart.hpp.

                                          { m_attachment.set(attachment_, time); }

Here is the call graph for this function:

Here is the caller graph for this function:

int DefaultRobot::calc_steps ( ) [private]

calc_steps() divides the velocity vector by the lenght of the kart, and gets the number of steps to use for the sight line of the kart.

The calling sequence guarantees that m_future_sector is not UNKNOWN.

Definition at line 813 of file default_robot.cpp.

{
    int steps = int( getVelocityLC().getY() / m_kart_properties->getKartLength() );
    if( steps < m_min_steps ) steps = m_min_steps;

    //Increase the steps depending on the width, if we steering hard,
    //mostly for curves.
    if( fabsf(m_controls.lr) > 0.95 )
    {
        const int WIDTH_STEPS = 
            (int)( world->m_track->getWidth()[m_future_sector] 
                   /( m_kart_properties->getKartLength() * 2.0 ) );

        steps += WIDTH_STEPS;
    }

    return steps;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void DefaultRobot::check_crashes ( const int  STEPS,
sgVec3 const  pos 
) [private]

Definition at line 569 of file default_robot.cpp.

{
    //Right now there are 2 kind of 'crashes': with other karts and another
    //with the track. The sight line is used to find if the karts crash with
    //each other, but the first step is twice as big as other steps to avoid
    //having karts too close in any direction. The crash with the track can
    //tell when a kart is going to get out of the track so it steers.

    btVector3 vel_normal;
       //in this func we use it as a 2d-vector, but later on it is passed
       //to world->m_track->findRoadSector, there it is used as a 3d-vector
       //to find distance to plane, so z must be initialized to zero
       sgVec3 step_coord;
    SGfloat kart_distance;

       step_coord[2] = 0.0;

    m_crashes.clear();

    const size_t NUM_KARTS = race_manager->getNumKarts();

    //Protection against having vel_normal with nan values
    const btVector3 &VEL = getVelocity();
    vel_normal.setValue(VEL.getX(), VEL.getY(), 0.0);
    float len=vel_normal.length();
    if(len>0.0f)
    {
        vel_normal/=len;
    }
    else
    {
        vel_normal.setValue(0.0, 0.0, 0.0);
    }

    for(int i = 1; STEPS > i; ++i)
    {
        sgAddScaledVec3( step_coord, pos, vel_normal, m_kart_properties->getKartLength() * i );

        /* Find if we crash with any kart, as long as we haven't found one
         * yet
         */
        if( m_crashes.m_kart == -1 )
        {
            for( unsigned int j = 0; j < NUM_KARTS; ++j )
            {
                const Kart* kart=world->getKart(j);
                if(kart==this||kart->isEliminated()) continue;   // ignore eliminated karts

                kart_distance = sgDistanceVec2( step_coord,
                    world->getKart(j)->getCoord()->xyz );

                if( kart_distance < m_kart_properties->getKartLength() + 0.125f * i )
                    if( getVelocityLC().getY() > world->getKart(j)->
                       getVelocityLC().getY() * 0.75f ) m_crashes.m_kart = j;
            }
        }

        /*Find if we crash with the drivelines*/
        world->m_track->findRoadSector(step_coord, &m_sector);

#ifdef SHOW_FUTURE_PATH

        ssgaSphere *sphere = new ssgaSphere;

#ifdef ERASE_PATH
        static ssgaSphere *last_sphere = 0;

        if( last_sphere ) scene->remove( last_sphere );

        last_sphere = sphere;
#endif

        sgVec3 center;
        center[0] = step_coord[0];
        center[1] = step_coord[1];
        center[2] = pos[2];
        sphere->setCenter( center );
        sphere->setSize( m_kart_properties->getKartLength() );
        if( m_sector == Track::UNKNOWN_SECTOR )
        {
            sgVec4 colour;
            colour[0] = colour[3] = 255;
            colour[1] = colour[2] = 0;
            sphere->setColour(colour);
        }
        else if( i == 1 )
        {
            sgVec4 colour;
            colour[0] = colour[1] = colour[2] = 0;
            colour[3] = 255;
            sphere->setColour( colour );
        }
        scene->add( sphere );
#endif

        m_future_location[0] = step_coord[0]; m_future_location[1] =
            step_coord[1];

        if( m_sector == Track::UNKNOWN_SECTOR )
        {
            m_future_sector = world->getTrack()->findOutOfRoadSector( step_coord,
                Track::RS_DONT_KNOW, m_future_sector );
            m_crashes.m_road = true;
            break;
        }
        else
        {
            m_future_sector = m_sector;
        }


    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Kart::collectedHerring ( Herring herring) [virtual, inherited]

Reimplemented in PlayerKart.

Definition at line 435 of file kart.cpp.

{
    const herringType TYPE = herring->getType();
    const int OLD_HERRING_GOBBLED = m_num_herrings_gobbled;

    switch (TYPE)
    {
    case HE_GREEN  : m_attachment.hitGreenHerring(); break;
    case HE_SILVER : m_num_herrings_gobbled++ ;       break;
    case HE_GOLD   : m_num_herrings_gobbled += 3 ;    break;
    case HE_RED    : int n=1 + 4*getNumHerring() / MAX_HERRING_EATEN;
        m_collectable.hitRedHerring(n); break;
    }   // switch TYPE

    if ( m_num_herrings_gobbled > MAX_HERRING_EATEN )
        m_num_herrings_gobbled = MAX_HERRING_EATEN;

    if(OLD_HERRING_GOBBLED < m_num_herrings_gobbled &&
       m_num_herrings_gobbled == MAX_HERRING_EATEN)
        sound_manager->playSfx(SOUND_FULL);
}   // hitHerring

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void Kart::crashed ( ) [inline, virtual, inherited]

Reimplemented in PlayerKart.

Definition at line 216 of file kart.hpp.

{};

Here is the caller graph for this function:

void Moveable::createBody ( float  mass,
btTransform trans,
btCollisionShape shape 
) [inherited]

Definition at line 80 of file moveable.cpp.

                                                   {
    
    btVector3 inertia;
    shape->calculateLocalInertia(mass, inertia);
    m_motion_state = new btDefaultMotionState(trans);

    btRigidBody::btRigidBodyConstructionInfo info(mass, m_motion_state, shape, inertia);
    info.m_restitution=0.5f;

    // Then create a rigid body
    // ------------------------
    m_body = new btRigidBody(info);
    // The value of user_pointer must be set from the actual class, otherwise this
    // is only a pointer to moveable, not to (say) kart, and virtual 
    // functions are not called correctly. So only init the pointer to zero.
    m_user_pointer.zero();
    m_body->setUserPointer(&m_user_pointer);
}   // createBody

Here is the call graph for this function:

Here is the caller graph for this function:

void Kart::createPhysics ( ssgEntity *  obj) [inherited]

Definition at line 101 of file kart.cpp.

{
    // First: Create the chassis of the kart
    // -------------------------------------

    float kart_width  = m_kart_properties->getKartWidth();
    float kart_length = m_kart_properties->getKartLength();
    float kart_height = m_kart_properties->getKartHeight();

    btBoxShape *shape = new btBoxShape(btVector3(0.5f*kart_width,
                                                 0.5f*kart_length,
                                                 0.5f*kart_height));
    btTransform shiftCenterOfGravity;
    shiftCenterOfGravity.setIdentity();
    // Shift center of gravity downwards, so that the kart 
    // won't topple over too easy. This must be between 0 and 0.5
    // (it's in units of kart_height)
    const float CENTER_SHIFT = getGravityCenterShift();
    shiftCenterOfGravity.setOrigin(btVector3(0.0f,0.0f,CENTER_SHIFT*kart_height));

    m_kart_chassis.addChildShape(shiftCenterOfGravity, shape);

    // Set mass and inertia
    // --------------------
    float mass=getMass();

    // Position the chassis
    // --------------------
    btTransform trans;
    trans.setIdentity();
    createBody(mass, trans, &m_kart_chassis);
    m_user_pointer.set(this);
    m_body->setDamping(m_kart_properties->getChassisLinearDamping(), 
                       m_kart_properties->getChassisAngularDamping() );

    // Reset velocities
    // ----------------
    m_body->setLinearVelocity (btVector3(0.0f,0.0f,0.0f));
    m_body->setAngularVelocity(btVector3(0.0f,0.0f,0.0f));

    // Create the actual vehicle
    // -------------------------
    m_vehicle_raycaster = 
        new btDefaultVehicleRaycaster(world->getPhysics()->getPhysicsWorld());
    m_tuning  = new btRaycastVehicle::btVehicleTuning();
    m_vehicle = new btRaycastVehicle(*m_tuning, m_body, m_vehicle_raycaster);

    // never deactivate the vehicle
    m_body->setActivationState(DISABLE_DEACTIVATION);
    m_vehicle->setCoordinateSystem(/*right: */ 0,  /*up: */ 2,  /*forward: */ 1);
    
    // Add wheels
    // ----------
    float wheel_width  = m_kart_properties->getWheelWidth();
    float wheel_radius = m_kart_properties->getWheelRadius();
    float suspension_rest = m_kart_properties->getSuspensionRest();
    float connection_height = -(0.5f-CENTER_SHIFT)*kart_height;
    btVector3 wheel_direction(0.0f, 0.0f, -1.0f);
    btVector3 wheel_axle(1.0f,0.0f,0.0f);

    // right front wheel
    btVector3 wheel_coord(0.5f*kart_width-0.3f*wheel_width,
                          0.5f*kart_length-wheel_radius,
                          connection_height);
    m_vehicle->addWheel(wheel_coord, wheel_direction, wheel_axle,
                        suspension_rest, wheel_radius, *m_tuning,
                        /* isFrontWheel: */ true);

    // left front wheel
    wheel_coord = btVector3(-0.5f*kart_width+0.3f*wheel_width,
                            0.5f*kart_length-wheel_radius,
                            connection_height);
    m_vehicle->addWheel(wheel_coord, wheel_direction, wheel_axle,
                        suspension_rest, wheel_radius, *m_tuning,
                        /* isFrontWheel: */ true);

    // right rear wheel
    wheel_coord = btVector3(0.5f*kart_width-0.3f*wheel_width, 
                            -0.5f*kart_length+wheel_radius,
                            connection_height);
    m_vehicle->addWheel(wheel_coord, wheel_direction, wheel_axle,
                        suspension_rest, wheel_radius, *m_tuning,
                        /* isFrontWheel: */ false);

    // right rear wheel
    wheel_coord = btVector3(-0.5f*kart_width+0.3f*wheel_width,
                            -0.5f*kart_length+wheel_radius,
                            connection_height);
    m_vehicle->addWheel(wheel_coord, wheel_direction, wheel_axle,
                        suspension_rest, wheel_radius, *m_tuning,
                        /* isFrontWheel: */ false);

    for(int i=0; i<m_vehicle->getNumWheels(); i++)
    {
        btWheelInfo& wheel               = m_vehicle->getWheelInfo(i);
        wheel.m_suspensionStiffness      = m_kart_properties->getSuspensionStiffness();
        wheel.m_wheelsDampingRelaxation  = m_kart_properties->getWheelDampingRelaxation();
        wheel.m_wheelsDampingCompression = m_kart_properties->getWheelDampingCompression();
        wheel.m_frictionSlip             = m_kart_properties->getFrictionSlip();
        wheel.m_rollInfluence            = m_kart_properties->getRollInfluence();
    }
    // Obviously these allocs have to be properly managed/freed
    btTransform t;
    t.setIdentity();
    m_uprightConstraint=new btUprightConstraint(*m_body, t);
    m_uprightConstraint->setLimit(m_kart_properties->getUprightTolerance());
    m_uprightConstraint->setBounce(0.0f);
    m_uprightConstraint->setMaxLimitForce(m_kart_properties->getUprightMaxForce());
    m_uprightConstraint->setErp(1.0f);
    m_uprightConstraint->setLimitSoftness(1.0f);
    m_uprightConstraint->setDamping(0.0f);
    world->getPhysics()->addKart(this, m_vehicle);
}   // createPhysics

Here is the call graph for this function:

Here is the caller graph for this function:

bool DefaultRobot::do_wheelie ( const int  STEPS) [private]

Definition at line 431 of file default_robot.cpp.

{
    if( m_crashes.m_road ) return false;
    if( m_crashes.m_kart != -1 ) return false;

    //We have to be careful with normalizing, because if the source argument
    //has both the X and Y axis set to 0, it returns nan to the destiny.
    const btVector3 &VEL=getVelocity();
    btVector3        vel_normal(VEL.getX(), VEL.getY(), 0.0);
    float            len=vel_normal.length();
    // Too slow for wheelies, and it avoids normalisation problems.
    if(len<getMaxSpeed()*getWheelieMaxSpeedRatio()) return false;
    vel_normal/=len;

    sgVec2 step_coord;
    sgVec3 step_track_coord;
    float distance;

    //FIXME: instead of using 1.5, it should find out how much time it
    //will pass to stop doing the wheelie completely from the current state.
    const float CHECK_DIST = 1.5f * m_wheelie_check_dist;

    /* The following method of finding if a position is outside of the track
       is less accurate than calling findRoadSector(), but a lot faster.
     */
    const int WHEELIE_STEPS = int(( getVelocityLC().getY() * CHECK_DIST )/
        m_kart_properties->getKartLength() );

    for( int i = WHEELIE_STEPS; i > STEPS - 1; --i )
    {
        sgAddScaledVec2( step_coord, m_curr_pos.xyz, vel_normal,
            m_kart_properties->getKartLength() * i );

        world->m_track->spatialToTrack( step_track_coord, step_coord,
            m_future_sector );

        distance = step_track_coord[0] > 0.0f ?  step_track_coord[0]
                   : -step_track_coord[0];

        if( distance > world->m_track->getWidth()[m_track_sector] )
        {
            return false;
        }
    }

    return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Kart::doLapCounting ( ) [virtual, inherited]

Reimplemented in TrafficDriver.

Definition at line 366 of file kart.cpp.

{
    bool newLap = m_last_track_coords[1] > 300.0f && m_curr_track_coords[1] <  20.0f;
    if ( newLap )
    {
        // Only increase the lap counter and set the new time if the
        // kart hasn't already finished the race (otherwise the race_gui
        // will begin another countdown).
        if(m_race_lap+1<=race_manager->getNumLaps())
        {
            setTimeAtLap(world->getTime());
            m_race_lap++ ;
        }
        // Only do timings if original time was set properly. Driving backwards
        // over the start line will cause the lap start time to be set to -1.
        if(m_lap_start_time>=0.0)
        {
            float time_per_lap;
            if (m_race_lap == 1) // just completed first lap
            {
              time_per_lap=world->getTime();
            }
            else //completing subsequent laps
            {
              time_per_lap=world->getTime()-m_lap_start_time;
            }
                        
            if(time_per_lap < world->getFastestLapTime() &&
                race_manager->raceHasLaps())
            {
                world->setFastestLap(this, time_per_lap);
                RaceGUI* m=(RaceGUI*)menu_manager->getRaceMenu();
                if(m)
                {
                    m->addMessage(_("New fastest lap"), NULL, 
                                  2.0f, 40, 100, 210, 100);
                    char s[20];
                    m->TimeToString(time_per_lap, s);
                    snprintf(m_fastest_lap_message, sizeof(m_fastest_lap_message),
                             "%s: %s",s, getName().c_str());
                    m->addMessage(m_fastest_lap_message, NULL, 
                                  2.0f, 40, 100, 210, 100);
                }   // if m
            }   // if time_per_lap < world->getFasterstLapTime()
            if(isPlayerKart())
            {
                // Put in in the highscore list???
                //printf("Time per lap: %s %f\n", getName().c_str(), time_per_lap);
            }
        }
        m_lap_start_time = world->getTime();
    }
    else if ( m_curr_track_coords[1] > 300.0f && m_last_track_coords[1] <  20.0f)
    {
        m_race_lap-- ;
        // Prevent cheating by setting time to a negative number, indicating
        // that the line wasn't crossed properly.
        m_lap_start_time = -1.0f;
    } else
    {   // Switch to fast music in case of follow the leader when only 3 karts are left
        if(race_manager->getRaceMode()==RaceManager::RM_FOLLOW_LEADER &&
            world->getCurrentNumKarts()==3)  
        {
            sound_manager->switchToFastMusic();
        }
    }
}   // doLapCounting

Here is the call graph for this function:

Here is the caller graph for this function:

void Kart::draw ( ) [inherited]

Definition at line 681 of file kart.cpp.

{
    float m[16];
    btTransform t=getTrans();
    t.getOpenGLMatrix(m);

    btVector3 wire_color(0.5f, 0.5f, 0.5f);
    world->getPhysics()->debugDraw(m, m_body->getCollisionShape(), 
                                   wire_color);
    btCylinderShapeX wheelShape( btVector3(0.3f,
                                        m_kart_properties->getWheelRadius(),
                                        m_kart_properties->getWheelRadius()));
    btVector3 wheelColor(1,0,0);
    for(int i=0; i<m_vehicle->getNumWheels(); i++)
    {
        m_vehicle->updateWheelTransform(i, true);
        float m[16];
        m_vehicle->getWheelInfo(i).m_worldTransform.getOpenGLMatrix(m);
        world->getPhysics()->debugDraw(m, &wheelShape, wheelColor);
    }
}   // draw

Here is the call graph for this function:

Here is the caller graph for this function:

void Kart::eliminate ( ) [inherited]

Definition at line 248 of file kart.cpp.

{
    m_eliminated = true;
    world->getPhysics()->removeKart(this);

    // make the kart invisible by placing it way under the track
    sgVec3 hell; hell[0]=0.0f; hell[1]=0.0f; hell[2] = -10000.0f;
    getModelTransform()->setTransform(hell);
}   // eliminate

Here is the call graph for this function:

Here is the caller graph for this function:

void Kart::endRescue ( ) [inherited]

Drops a kart which was rescued back on the track.

Definition at line 867 of file kart.cpp.

{
    if ( m_track_sector > 0 ) m_track_sector-- ;
    world ->m_track -> trackToSpatial ( m_curr_pos.xyz, m_track_sector ) ;
    m_curr_pos.hpr[0] = world->m_track->m_angle[m_track_sector] ;
    m_rescue = false ;

    m_body->setLinearVelocity (btVector3(0.0f,0.0f,0.0f));
    m_body->setAngularVelocity(btVector3(0.0f,0.0f,0.0f));
    // FIXME: This code positions the kart correctly back on the track
    // (nearest waypoint) - but if the kart is simply upside down,
    // it feels better if the kart is left where it was. Perhaps
    // this code should only be used if a rescue was not triggered
    // by the kart being upside down??
    btTransform pos;
    // A certain epsilon is added here to the Z coordinate (0.1), in case
    // that the drivelines are somewhat under the track. Otherwise, the
    // kart will be placed a little bit under the track, triggering
    // a rescue, ...
    pos.setOrigin(btVector3(m_curr_pos.xyz[0],m_curr_pos.xyz[1],
                            m_curr_pos.xyz[2]+0.5f*getKartHeight()+0.1f));
    pos.setRotation(btQuaternion(btVector3(0.0f, 0.0f, 1.0f), 
                                 DEGREE_TO_RAD(world->m_track->m_angle[m_track_sector])));
    m_body->setCenterOfMassTransform(pos);
    world->getPhysics()->addKart(this, m_vehicle);
    setTrans(pos);
}   // endRescue

Here is the call graph for this function:

Here is the caller graph for this function:

float Kart::estimateFinishTime ( ) [inherited]

Definition at line 1077 of file kart.cpp.

{
    // Estimate the arrival time of any karts that haven't arrived
    // yet by using their average speed up to now and the distance
    // still to race. This approach guarantees that the order of 
    // the karts won't change anymore (karts ahead will have a 
    // higher average speed and therefore finish the race earlier 
    // than karts further behind), so the position doesn't have to
    // be updated to get the correct scoring.
    float distance_covered  = getLap()*world->m_track->getTrackLength()
                            + getDistanceDownTrack();
    // In case that a kart is rescued behind start line, or ...
    if(distance_covered<0) distance_covered =1.0f;

    float average_speed     = distance_covered/world->getTime();

    // Finish time is the time needed for the whole race with 
    // the average speed computed above.
    return race_manager->getNumLaps()*world->getTrack()->getTrackLength() 
          / average_speed;

}   // estimateFinishTime

Here is the call graph for this function:

void DefaultRobot::find_curve ( ) [private]

Find_curve() gathers info about the closest sectors ahead: the curve angle, the direction of the next turn, and the optimal speed at which the curve can be travelled at it's widest angle.

The number of sectors that form the curve is dependant on the kart's speed.

Definition at line 929 of file default_robot.cpp.

{
    const int DRIVELINE_SIZE = (unsigned int)world->m_track->m_driveline.size();
    float total_dist = 0.0f;
    int next_hint = m_track_sector;
    int i;

    for(i = m_track_sector; total_dist < getVelocityLC().getY(); i = next_hint)
    {
        next_hint = i + 1 < DRIVELINE_SIZE ? i + 1 : 0;
        total_dist += sgDistanceVec2(world->m_track->m_driveline[i], world->m_track->m_driveline[next_hint]);
    }


    m_curve_angle = normalize_angle(world->m_track->m_angle[i] - world->m_track->m_angle[m_track_sector]);
    m_inner_curve = m_curve_angle > 0.0 ? -1 : 1;
    // FIXME: 0.9 is the tire grip - but this was never used. For now this
    // 0.9 is left in place to reproduce the same results and AI behaviour,
    // but this function should be updated to bullet physics
    m_curve_target_speed = sgSqrt(get_approx_radius(m_track_sector, i) * world->m_track->getGravity() * 0.9f);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void DefaultRobot::find_non_crashing_point ( sgVec2  result) [private]

Find the sector that at the longest distance from the kart, that can be driven to without crashing with the track, then find towards which of the two edges of the track is closest to the next curve after wards, and return the position of that edge.

Definition at line 689 of file default_robot.cpp.

{
    const unsigned int DRIVELINE_SIZE = (unsigned int)world->m_track->m_driveline.size();

    unsigned int sector = (unsigned int)m_track_sector + 1 < DRIVELINE_SIZE ?
        m_track_sector + 1 : 0;
    int target_sector;

    sgVec2 direction;
    sgVec3 step_track_coord;
    SGfloat distance;
    int steps;

    //We exit from the function when we have found a solution
    while( 1 )
    {
        //target_sector is the sector at the longest distance that we can drive
        //to without crashing with the track.
        target_sector = sector + 1 < DRIVELINE_SIZE ? sector + 1 : 0;

        //direction is a vector from our kart to the sectors we are testing
        sgSubVec2( direction, world->m_track->m_driveline[target_sector],
            m_curr_pos.xyz );

        float len=sgLengthVec2(direction);
        steps = int( len / m_kart_properties->getKartLength() );
        if( steps < 3 ) steps = 3;

        //Protection against having vel_normal with nan values
        if(len>0.0f) {
            sgScaleVec2(direction, 1.0f/len);
        }

        sgVec2 step_coord;
        //Test if we crash if we drive towards the target sector
        for( int i = 2; i < steps; ++i )
        {
            sgAddScaledVec2( step_coord, m_curr_pos.xyz, direction,
                m_kart_properties->getKartLength() * i );

            world->m_track->spatialToTrack( step_track_coord, step_coord,
                sector );

            distance = step_track_coord[0] > 0.0f ? step_track_coord[0]
                       : -step_track_coord[0];

            //If we are outside, the previous sector is what we are looking for
            if ( distance + m_kart_properties->getKartLength() * 0.5f > world->
                m_track->getWidth()[sector] )
            {
                sgCopyVec2( result, world->m_track->m_driveline[sector] );

#ifdef SHOW_NON_CRASHING_POINT
                ssgaSphere *sphere = new ssgaSphere;

                static ssgaSphere *last_sphere = 0;

                if(last_sphere) scene->remove( last_sphere );

                last_sphere = sphere;

                sgVec3 center;
                center[0] = result[0];
                center[1] = result[1];
                center[2] = m_curr_pos.xyz[2];
                sphere->setCenter( center );
                sphere->setSize( 0.5f );

                sgVec4 colour;
                colour[1] = colour[3] = 255;
                colour[0] = colour[2] = 0;
                sphere->setColour( colour );

                scene->add( sphere );
#endif

                return;
            }
        }
        sector = target_sector;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Kart::forceRescue ( bool  is_rescue = false) [inherited]

Definition at line 853 of file kart.cpp.

{
    m_rescue=true;
    // If rescue is triggered while doing a shortcut, reset the kart to the
    // segment where the shortcut started!! And then reset the shortcut
    // flag, so that this shortcut is not counted!
    if(is_shortcut)
    {
        m_track_sector   = m_shortcut_sector;
    } 
}   // forceRescue

Here is the caller graph for this function:

float DefaultRobot::get_approx_radius ( const int  START,
const int  END 
) const [private]

Finds the approximate radius of a track's curve.

It needs two arguments, the number of the drivepoint that marks the beginning of the curve, and the number of the drivepoint that marks the ending of the curve.

Based on that you can construct any circle out of 3 points in it, we use the two arguments to use the drivelines as the first and last point; the middle sector is averaged.

Definition at line 855 of file default_robot.cpp.

{
    const int MIDDLE = (START + END) / 2;

    //If the START and END sectors are very close, their average will be one
    //of them, and using twice the same point just generates a huge radius
    //(too big to be of any use) but it also can generate a division by zero,
    //so here is some special handling for that case.
    if (MIDDLE == START || MIDDLE == END ) return 99999.0f;

    float X1, Y1, X2, Y2, X3, Y3;

    //The next line is just to avoid compiler warnings.
    X1 = X2 = X3 = Y1 = Y2 = Y3 = 0.0;


    if(m_inner_curve == -1)
    {

    X1 = world->m_track->m_left_driveline[START][0];
    Y1 = world->m_track->m_left_driveline[START][1];

    X2 = world->m_track->m_left_driveline[MIDDLE][0];
    Y2 = world->m_track->m_left_driveline[MIDDLE][1];

    X3 = world->m_track->m_left_driveline[END][0];
    Y3 = world->m_track->m_left_driveline[END][1];
    }else if (m_inner_curve == 0)
    {
    X1 = world->m_track->m_driveline[START][0];
    Y1 = world->m_track->m_driveline[START][1];

    X2 = world->m_track->m_driveline[MIDDLE][0];
    Y2 = world->m_track->m_driveline[MIDDLE][1];

    X3 = world->m_track->m_driveline[END][0];
    Y3 = world->m_track->m_driveline[END][1];
    }else if (m_inner_curve == 1)
    {
    X1 = world->m_track->m_right_driveline[START][0];
    Y1 = world->m_track->m_right_driveline[START][1];

    X2 = world->m_track->m_right_driveline[MIDDLE][0];
    Y2 = world->m_track->m_right_driveline[MIDDLE][1];

    X3 = world->m_track->m_right_driveline[END][0];
    Y3 = world->m_track->m_right_driveline[END][1];
    }

    const float A = X2 - X1;
    const float B = Y2 - Y1;
    const float C = X3 - X1;
    const float D = Y3 - Y1;

    const float E = A * ( X1 + X2) + B * (Y1 + Y2);
    const float F = C * ( X1 + X3) + D * (Y1 + Y3);

    const float G = 2.0f * ( A*( Y3-Y2 ) - B*( X3 - X2 ) );

    const float pX = ( D*E - B*F) / G;
    const float pY = ( A*F - C*E) / G;

    const float radius = sqrt( ( X1 - pX) * ( X1 - pX) + (Y1 - pY) * (Y1 - pY) );

    return radius;
}

Here is the caller graph for this function:

float Kart::getActualWheelForce ( ) [inherited]

Definition at line 459 of file kart.cpp.

{
    float zipperF=(m_zipper_time_left>0.0f) ? stk_config->m_zipper_force : 0.0f;
    const std::vector<float>& gear_ratio=m_kart_properties->getGearSwitchRatio();
    for(unsigned int i=0; i<gear_ratio.size(); i++)
    {
        if(m_speed <= m_max_speed*gear_ratio[i]) 
            return getMaxPower()*m_kart_properties->getGearPowerIncrease()[i]+zipperF;
    }
    return getMaxPower()+zipperF;

}   // getActualWheelForce

Here is the call graph for this function:

Here is the caller graph for this function:

Attachment* Kart::getAttachment ( ) [inline, inherited]

Definition at line 135 of file kart.hpp.

{ return &m_attachment;          }

Here is the caller graph for this function:

btRigidBody* Moveable::getBody ( ) const [inline, inherited]

Definition at line 77 of file moveable.hpp.

{return m_body; }

Here is the caller graph for this function:

float Kart::getBrakeFactor ( ) const [inline, inherited]

Definition at line 165 of file kart.hpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void Kart::getClosestKart ( float *  cdist,
int *  closest 
) [inherited]
Collectable* Kart::getCollectable ( ) [inline, inherited]

Definition at line 139 of file kart.hpp.

{ return &m_collectable;         }

Here is the caller graph for this function:

const sgVec3* Kart::getColor ( ) const [inline, inherited]

Definition at line 157 of file kart.hpp.

Here is the call graph for this function:

Here is the caller graph for this function:

sgCoord* Moveable::getCoord ( ) [inline, inherited]

Definition at line 66 of file moveable.hpp.

{return &m_curr_pos;                }

Here is the caller graph for this function:

const sgCoord* Moveable::getCoord ( ) const [inline, inherited]

Definition at line 68 of file moveable.hpp.

{return &m_curr_pos;                }
float Kart::getDistanceDownTrack ( ) const [inline, inherited]

Definition at line 133 of file kart.hpp.

{ return m_curr_track_coords[1]; }

Here is the caller graph for this function:

float Kart::getDistanceToCenter ( ) const [inline, inherited]

Definition at line 134 of file kart.hpp.

{ return m_curr_track_coords[0]; }

Here is the caller graph for this function:

float Kart::getFinishTime ( ) const [inline, inherited]

Definition at line 146 of file kart.hpp.

{ return m_finish_time;         }

Here is the caller graph for this function:

float Kart::getFrictionSlip ( ) const [inline, inherited]

Definition at line 168 of file kart.hpp.

Here is the call graph for this function:

Here is the caller graph for this function:

float Kart::getGravityCenterShift ( ) const [inline, inherited]

Definition at line 170 of file kart.hpp.

Here is the call graph for this function:

Here is the caller graph for this function:

float Kart::getHeightCOG ( ) const [inline, inherited]

Definition at line 167 of file kart.hpp.

Here is the call graph for this function:

float TerrainInfo::getHoT ( ) const [inline, inherited]

Definition at line 44 of file terrain_info.hpp.

{ return m_HoT;      }

Here is the caller graph for this function:

int Kart::getInitialPosition ( ) const [inline, inherited]

Definition at line 144 of file kart.hpp.

{ return  m_initial_position;    }

Here is the caller graph for this function:

float Kart::getKartHeight ( ) const [inline, inherited]

Definition at line 190 of file kart.hpp.

Here is the call graph for this function:

Here is the caller graph for this function:

float Kart::getKartLength ( ) const [inline, inherited]

Definition at line 189 of file kart.hpp.

Here is the call graph for this function:

Here is the caller graph for this function:

const KartProperties* Kart::getKartProperties ( ) const [inline, inherited]

Definition at line 123 of file kart.hpp.

{ return m_kart_properties; }

Here is the caller graph for this function:

int Kart::getLap ( ) const [inline, inherited]

Definition at line 142 of file kart.hpp.

{ return  m_race_lap;            }

Here is the caller graph for this function:

float Kart::getMass ( ) const [inline, inherited]

Definition at line 158 of file kart.hpp.

Here is the call graph for this function:

Here is the caller graph for this function:

const Material* TerrainInfo::getMaterial ( ) const [inline, inherited]

Definition at line 45 of file terrain_info.hpp.

{ return m_material; }

Here is the caller graph for this function:

float Kart::getMaxPower ( ) const [inline, inherited]

Definition at line 163 of file kart.hpp.

Here is the call graph for this function:

Here is the caller graph for this function:

float Kart::getMaxSpeed ( ) const [inline, inherited]

Definition at line 185 of file kart.hpp.

{return m_max_speed;              }

Here is the caller graph for this function:

float Kart::getMaxSteerAngle ( ) const [inline, inherited]

Definition at line 169 of file kart.hpp.

Here is the call graph for this function:

Here is the caller graph for this function:

ssgTransform* Moveable::getModelTransform ( ) [inline, inherited]

Definition at line 62 of file moveable.hpp.

{return m_model_transform;          }

Here is the caller graph for this function:

const std::string& Kart::getName ( ) const [inline, inherited]

Definition at line 209 of file kart.hpp.

Here is the call graph for this function:

Here is the caller graph for this function:

const btVector3& TerrainInfo::getNormal ( ) const [inline, inherited]

Definition at line 46 of file terrain_info.hpp.

{ return m_normal;   }
const sgVec4* Moveable::getNormalHOT ( ) const [inline, inherited]

Definition at line 69 of file moveable.hpp.

{return m_normal_hot;               }
int Kart::getNumCollectables ( ) const [inline, inherited]

Definition at line 140 of file kart.hpp.

{ return  m_collectable.getNum();}

Here is the call graph for this function:

Here is the caller graph for this function:

int Kart::getNumHerring ( ) const [inline, inherited]

Definition at line 141 of file kart.hpp.

Here is the caller graph for this function:

const btVector3 Moveable::getPos ( ) const [inline, inherited]

Definition at line 67 of file moveable.hpp.

{return m_transform.getOrigin();    }

Here is the call graph for this function:

Here is the caller graph for this function:

int Kart::getPosition ( ) const [inline, inherited]

Definition at line 143 of file kart.hpp.

{ return  m_race_position;       }

Here is the caller graph for this function:

int Kart::getSector ( ) const [inline, inherited]

Definition at line 132 of file kart.hpp.

{ return m_track_sector;         }

Here is the caller graph for this function:

float Kart::getSpeed ( ) const [inline, inherited]

Definition at line 198 of file kart.hpp.

{return m_speed;                 }

Here is the caller graph for this function:

float Kart::getSteerAngle ( ) const [inline, inherited]

Definition at line 182 of file kart.hpp.

Here is the call graph for this function:

float Kart::getSteerPercent ( ) const [inline, inherited]

Definition at line 184 of file kart.hpp.

{return m_controls.lr;            }

Here is the caller graph for this function:

float TerrainInfo::getTerrainPitch ( float  heading) const [inherited]

Returns the pitch of the terrain depending on the heading.

Definition at line 49 of file terrain_info.cpp.

                                                      {
    if(m_HoT==Track::NOHIT) return 0.0f;

    const float X =-sin(heading);
    const float Y = cos(heading);
    // Compute the angle between the normal of the plane and the line to
    // (x,y,0).  (x,y,0) is normalised, so are the coordinates of the plane,
    // simplifying the computation of the scalar product.
    float pitch = ( m_normal.getX()*X + m_normal.getY()*Y );  // use ( x,y,0)
        
    // The actual angle computed above is between the normal and the (x,y,0)
    // line, so to compute the actual angles 90 degrees must be subtracted.
    pitch = acosf(pitch) - NINETY_DEGREE_RAD;
    return pitch;
}   // getTerrainPitch

Here is the call graph for this function:

Here is the caller graph for this function:

float Kart::getTimeAtLap ( ) const [inline, inherited]

Definition at line 187 of file kart.hpp.

{return m_time_at_last_lap;       }

Here is the caller graph for this function:

float Kart::getTimeFullSteer ( ) const [inline, inherited]

Definition at line 164 of file kart.hpp.

Here is the call graph for this function:

Here is the caller graph for this function:

const btTransform& Moveable::getTrans ( ) const [inline, inherited]

Definition at line 80 of file moveable.hpp.

{return m_transform;}

Here is the caller graph for this function:

btUprightConstraint* Kart::getUprightConstraint ( ) const [inline, inherited]

Definition at line 193 of file kart.hpp.

Here is the caller graph for this function:

btRaycastVehicle* Kart::getVehicle ( ) const [inline, inherited]

Definition at line 192 of file kart.hpp.

{return m_vehicle;                }

Here is the caller graph for this function:

virtual const btVector3& Moveable::getVelocity ( ) const [inline, virtual, inherited]

Reimplemented in Homing.

Definition at line 63 of file moveable.hpp.

Here is the call graph for this function:

Here is the caller graph for this function:

const btVector3& Moveable::getVelocityLC ( ) const [inline, inherited]

Definition at line 64 of file moveable.hpp.

{return m_velocityLC;               }

Here is the caller graph for this function:

float Kart::getWheelBase ( ) const [inline, inherited]

Definition at line 166 of file kart.hpp.

Here is the call graph for this function:

float Kart::getWheelieAngle ( ) const [inline, inherited]

Definition at line 191 of file kart.hpp.

{return m_wheelie_angle;          }
float Kart::getWheelieMaxPitch ( ) const [inline, inherited]

Definition at line 174 of file kart.hpp.

Here is the call graph for this function:

Here is the caller graph for this function:

float Kart::getWheelieMaxSpeedRatio ( ) const [inline, inherited]

Definition at line 172 of file kart.hpp.

Here is the call graph for this function:

Here is the caller graph for this function:

float Kart::getWheeliePitchRate ( ) const [inline, inherited]

Definition at line 176 of file kart.hpp.

Here is the call graph for this function:

Here is the caller graph for this function:

float Kart::getWheelieRestoreRate ( ) const [inline, inherited]

Definition at line 178 of file kart.hpp.

Here is the call graph for this function:

Here is the caller graph for this function:

float Kart::getWheelieSpeedBoost ( ) const [inline, inherited]

Definition at line 180 of file kart.hpp.

Here is the call graph for this function:

void DefaultRobot::handle_acceleration ( const float  DELTA) [private]

Definition at line 393 of file default_robot.cpp.

{
    //Do not accelerate until we have delayed the start enough
    if( m_time_till_start > 0.0f )
    {
        m_time_till_start -= DELTA;
        m_controls.accel = 0.0f;
        return;
    }

    if( m_controls.brake == true )
    {
        m_controls.accel = 0.0f;
        return;
    }

    if( m_wait_for_players )
    {
        //Find if any player is ahead of this kart
        bool player_winning = false;
        for(unsigned int i = 0; i < race_manager->getNumPlayers(); ++i )
            if( m_race_position > world->getPlayerKart(i)->getPosition() )
            {
                player_winning = true;
                break;
            }

        if( player_winning )
        {
            m_controls.accel = m_max_handicap_accel;
            return;
        }
    }

    m_controls.accel = 1.0f;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void DefaultRobot::handle_braking ( ) [private]

Definition at line 145 of file default_robot.cpp.

{
    // In follow the leader mode, the kart should brake if they are ahead of
    // the leader (and not the leader, i.e. don't have initial position 1)
    if(race_manager->getRaceMode()==RaceManager::RM_FOLLOW_LEADER &&
        getPosition()<world->getKart(0)->getPosition()            &&
        getInitialPosition()>1                                       )
    {
        m_controls.brake = true;
        return;
    }
    const float MIN_SPEED = world->m_track->getWidth()[m_track_sector];

    //We may brake if we are about to get out of the road, but only if the
    //kart is on top of the road, and if we won't slow down below a certain
    //limit.
    if ( m_crashes.m_road && m_on_road && getVelocityLC().getY() > MIN_SPEED)
    {
        float kart_ang_diff = world->m_track->m_angle[m_track_sector] -
            m_curr_pos.hpr[0];
        kart_ang_diff = normalize_angle(kart_ang_diff);
        kart_ang_diff = fabsf(kart_ang_diff);

        const float MIN_TRACK_ANGLE = 20.0f;
        const float CURVE_INSIDE_PERC = 0.25f;

        //Brake only if the road does not goes somewhat straight.
        if(m_curve_angle > MIN_TRACK_ANGLE) //Next curve is left
        {
            //Avoid braking if the kart is in the inside of the curve, but
            //if the curve angle is bigger than what the kart can steer, brake
            //even if we are in the inside, because the kart would be 'thrown'
            //out of the curve.
            if(!(m_curr_track_coords[0] > world->m_track->
                getWidth()[m_track_sector] * -CURVE_INSIDE_PERC ||
                m_curve_angle > getMaxSteerAngle()))
            {
                m_controls.brake = false;
                return;
            }
        }
        else if( m_curve_angle < -MIN_TRACK_ANGLE ) //Next curve is right
        {
            if(!(m_curr_track_coords[0] < world->m_track->
                getWidth()[m_track_sector] * CURVE_INSIDE_PERC ||
                m_curve_angle < -getMaxSteerAngle()))
            {
                m_controls.brake = false;
                return;
            }
        }

        //Brake if the kart's speed is bigger than the speed we need
        //to go through the curve at the widest angle, or if the kart
        //is not going straight in relation to the road.
        float angle_adjust = world->m_track->getAIAngleAdjustment();
        float speed_adjust = world->m_track->getAICurveSpeedAdjustment();
        if(getVelocityLC().getY() > speed_adjust*m_curve_target_speed ||
           kart_ang_diff          > angle_adjust*MIN_TRACK_ANGLE         )
        {
#ifdef AI_DEBUG
        std::cout << "BRAKING" << std::endl;
#endif
            m_controls.brake = true;
            return;
        }

    }

    m_controls.brake = false;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void DefaultRobot::handle_items ( const float  DELTA,
const int  STEPS 
) [private]

Definition at line 316 of file default_robot.cpp.

{
    m_controls.fire = false;

    if(isRescue() )
    {
        return;
    }

    m_time_since_last_shot += DELTA;
    if( m_collectable.getType() != COLLECT_NOTHING )
    {
        switch( m_item_tactic )
        {
        case IT_TEN_SECONDS:
            if( m_time_since_last_shot > 10.0f )
            {
                m_controls.fire = true;
                m_time_since_last_shot = 0.0f;
            }
            break;
        case IT_CALCULATE:
            switch( m_collectable.getType() )
            {
            case COLLECT_ZIPPER:
                {
                    const float ANGLE_DIFF = fabsf( normalize_angle(
                        world->m_track->m_angle[m_track_sector]-
                        m_curr_pos.hpr[0] ) );

                    if( m_time_since_last_shot > 10.0f && ANGLE_DIFF <
                        15.0f && !m_crashes.m_road && STEPS > 8 )
                    {
                        m_controls.fire = true;
                        m_time_since_last_shot = 0.0f;
                    }
                }
                break;

            case COLLECT_MISSILE:
            case COLLECT_HOMING:
                if( m_time_since_last_shot > 5.0f && m_crashes.m_kart != -1 )
                {
                    if( sgDistanceVec2( m_curr_pos.xyz,
                        world->getKart(m_crashes.m_kart)->getCoord()->xyz ) >
                        m_kart_properties->getKartLength() * 2.5f )
                    {
                        m_controls.fire = true;
                        m_time_since_last_shot = 0.0f;
                    }
                }
                break;

            case COLLECT_SPARK:
                if ( m_time_since_last_shot > 3.0f && m_crashes.m_kart != -1 )
                {
                    m_controls.fire = true;
                    m_time_since_last_shot = 0.0f;
                }
                break;
            default:
                m_controls.fire = true;
                m_time_since_last_shot = 0.0f;
                return;
            }
            break;
        }
    }

    if( m_controls.fire )
    {
        m_collectable.use() ;
    }
    return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void DefaultRobot::handle_race_start ( ) [private]

Definition at line 480 of file default_robot.cpp.

{
    //FIXME: make karts able to get a penalty for accelerating too soon
    //like players, should happen to about 20% of the karts in easy,
    //5% in medium and less than 1% of the karts in hard.
    if( m_time_till_start <  0.0f )
    {
        srand(( unsigned ) time( 0 ));

        //Each kart starts at a different, random time, and the time is
        //smaller depending on the difficulty.
        m_time_till_start = ( float ) rand() / RAND_MAX * m_max_start_delay;
    }
}

Here is the caller graph for this function:

void DefaultRobot::handle_rescue ( const float  DELTA) [private]

Definition at line 496 of file default_robot.cpp.

{
    //TODO: check if we collided against a dynamic object (ej.:kart) or
    //against the track's static object.
    //The m_crash_time measures if a kart has been crashing for too long
    m_crash_time += (m_collided && isOnGround()) ? 3.0f * DELTA : -0.25f * DELTA;

    if( m_crash_time < 0.0f ) m_crash_time = 0.0f;

    //Reaction to being stuck
    if( m_crash_time > 3.0f )
    {
        forceRescue();
        m_crash_time = 0.0f;
    }


    // check if kart is stuck
    if(getVehicle()->getRigidBody()->getLinearVelocity().length()<2.0f &&
       !isRescue() && !world->isStartPhase())
    {
        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;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void DefaultRobot::handle_steering ( ) [private]

Definition at line 218 of file default_robot.cpp.

{
    const unsigned int DRIVELINE_SIZE = (unsigned int)world->m_track->m_driveline.size();
    const size_t NEXT_SECTOR = (unsigned int)m_track_sector + 1 < DRIVELINE_SIZE ?
        m_track_sector + 1 : 0;
    float steer_angle = 0.0f;

    /*The AI responds based on the information we just gathered, using a
     *finite state machine.
     */
    //Reaction to being outside of the road
    if( fabsf(m_curr_track_coords[0]) + 0.5 >
        world->m_track->getWidth()[m_track_sector] )
    {
        steer_angle = steer_to_point( world->m_track->
            m_driveline[NEXT_SECTOR] );

#ifdef AI_DEBUG
        std::cout << "- Outside of road: steer to center point." <<
            std::endl;
#endif
    }
    //If we are going to crash against a kart, avoid it if it doesn't
    //drives the kart out of the road
    else if( m_crashes.m_kart != -1 && !m_crashes.m_road )
    {
        //-1 = left, 1 = right, 0 = no crash.
        if( m_start_kart_crash_direction == 1 )
        {
            steer_angle = steer_to_angle( NEXT_SECTOR, -90.0f );
            m_start_kart_crash_direction = 0;
        }
        else if(m_start_kart_crash_direction == -1)
        {
            steer_angle = steer_to_angle( NEXT_SECTOR, 90.0f );
            m_start_kart_crash_direction = 0;
        }
        else
        {
            if(m_curr_track_coords[0] > world->getKart(m_crashes.m_kart)->
               getDistanceToCenter())
            {
                steer_angle = steer_to_angle( NEXT_SECTOR, -90.0f );
                m_start_kart_crash_direction = 1;
            }
            else
            {
                steer_angle = steer_to_angle( NEXT_SECTOR, 90.0f );
                m_start_kart_crash_direction = -1;
            }
        }

#ifdef AI_DEBUG
        std::cout << "- Velocity vector crashes with kart and doesn't " <<
            "crashes with road : steer 90 degrees away from kart." <<
            std::endl;
#endif

    }
    else
    {
        switch( m_fallback_tactic )
        {
        case FT_FAREST_POINT:
            {
                sgVec2 straight_point;
                find_non_crashing_point( straight_point );
                steer_angle = steer_to_point( straight_point );
            }
            break;

        case FT_PARALLEL:
            steer_angle = steer_to_angle( NEXT_SECTOR, 0.0f );
            break;

        case FT_AVOID_TRACK_CRASH:
            if( m_crashes.m_road )
            {
                steer_angle = steer_to_angle( m_track_sector, 0.0f );
            }
            else steer_angle = 0.0f;

            break;
        }

#ifdef AI_DEBUG
        std::cout << "- Fallback."  << std::endl;
#endif

    }
    // avoid steer vibrations
    if (fabsf(steer_angle) < 2.0f)
        steer_angle = 0.f;

    m_controls.lr = angle_to_control( steer_angle );
}

Here is the call graph for this function:

Here is the caller graph for this function:

void DefaultRobot::handle_wheelie ( const int  STEPS) [private]

Definition at line 136 of file default_robot.cpp.

{
    if( m_use_wheelies )
    {
        m_controls.wheelie = do_wheelie( STEPS );
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Kart::handleExplosion ( const btVector3 pos,
bool  direct_hit 
) [inherited]

Definition at line 483 of file kart.cpp.

{
    if(direct_hit) 
    {
        btVector3 diff((float)(rand()%16/16), (float)(rand()%16/16), 2.0f);
        diff.normalize();
        diff*=stk_config->m_explosion_impulse/5.0f;
        this->m_uprightConstraint->setDisableTime(10.0f);
        getVehicle()->getRigidBody()->applyCentralImpulse(diff);
        getVehicle()->getRigidBody()->applyTorqueImpulse(btVector3(float(rand()%32*5),
                                                                   float(rand()%32*5),
                                                                   float(rand()%32*5)));
    }
    else  // only affected by a distant explosion
    {
        btVector3 diff=getPos()-pos;
        //if the z component is negative, the resulting impulse could push the 
        // kart through the floor. So in this case ignore z.
        if(diff.getZ()<0) diff.setZ(0.0f);
        float len2=diff.length2();

        // The correct formhale would be to first normalise diff,
        // then apply the impulse (which decreases 1/r^2 depending
        // on the distance r), so:
        // diff/len(diff) * impulseSize/len(diff)^2
        // = diff*impulseSize/len(diff)^3
        // We use diff*impulseSize/len(diff)^2 here, this makes the impulse
        // somewhat larger, which is actually more fun :)
        diff *= stk_config->m_explosion_impulse/len2;
        getVehicle()->getRigidBody()->applyCentralImpulse(diff);
    }
}   // handleExplosion

Here is the call graph for this function:

Here is the caller graph for this function:

float Kart::handleWheelie ( float  dt) [inherited]

Returned an additional engine power boost when doing a wheele.

Definition at line 707 of file kart.cpp.

{
    // Handle wheelies
    // ===============
    if ( m_controls.wheelie && 
         m_speed >= getMaxSpeed()*getWheelieMaxSpeedRatio())
    {
        // Disable the upright constraint, since it will otherwise
        // work against the wheelie
        m_uprightConstraint->setLimit(M_PI);

        if ( m_wheelie_angle < getWheelieMaxPitch() )
            m_wheelie_angle += getWheeliePitchRate() * dt;
        else
            m_wheelie_angle = getWheelieMaxPitch();
    }
    else if ( m_wheelie_angle > 0.0f )
    {
        m_wheelie_angle -= getWheelieRestoreRate() * dt;
        if ( m_wheelie_angle <= 0.0f ) m_wheelie_angle = 0.0f ;
    }
    if(m_wheelie_angle <=0.0f) 
    {
        m_uprightConstraint->setLimit(m_kart_properties->getUprightTolerance());
        return 0.0f;
    }

    const btTransform& chassisTrans = getTrans();
    btVector3 targetUp(0.0f, 0.0f, 1.0f);
    btVector3 forwardW (chassisTrans.getBasis()[0][1],
                        chassisTrans.getBasis()[1][1],
                        chassisTrans.getBasis()[2][1]);
    btVector3 crossProd = targetUp.cross(forwardW);
    crossProd.normalize();

    return m_kart_properties->getWheeliePowerBoost() * getMaxPower()
          * m_wheelie_angle/getWheelieMaxPitch();
}   // handleWheelie

Here is the call graph for this function:

Here is the caller graph for this function:

void Kart::handleZipper ( ) [virtual, inherited]

Reimplemented from Moveable.

Reimplemented in PlayerKart.

Definition at line 664 of file kart.cpp.

{
    // Ignore a zipper that's activated while braking
    if(m_controls.brake) return;
    m_zipper_time_left  = stk_config->m_zipper_time;
    const btVector3& v  = m_body->getLinearVelocity();
    float current_speed = v.length();
    float speed         = std::min(current_speed+stk_config->m_zipper_speed_gain, 
                                   getMaxSpeed());
    // Avoid NAN problems, which can happen if e.g. a kart is rescued on
    // top of zipper, and then dropped.
    if(current_speed>0.00001) m_body->setLinearVelocity(v*(speed/current_speed));
}   // handleZipper

Here is the call graph for this function:

Here is the caller graph for this function:

bool Kart::isEliminated ( ) const [inline, inherited]

Definition at line 202 of file kart.hpp.

{return m_eliminated;}

Here is the caller graph for this function:

bool Kart::isInRest ( ) const [inherited]

Returns true if the kart is 'resting'.

Returns true if the kart is 'resting', i.e. (nearly) not moving.

Definition at line 263 of file kart.cpp.

{
    return fabs(m_body->getLinearVelocity ().z())<0.2;
}  // isInRest

Here is the call graph for this function:

bool Kart::isOnGround ( ) const [inherited]

The kart is on ground if all 4 wheels touch the ground.

Definition at line 475 of file kart.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

int DefaultRobot::isPlayerKart ( ) const [inline, virtual]

Reimplemented from AutoKart.

Definition at line 135 of file default_robot.hpp.

{return 0;}
bool Kart::isRescue ( ) const [inline, inherited]

Definition at line 204 of file kart.hpp.

{return m_rescue;}

Here is the caller graph for this function:

void Kart::load_wheels ( ssgBranch *  obj) [protected, inherited]

Search the given branch of objects that match the wheel names and if so assign them to wheel_* variables.

Definition at line 934 of file kart.cpp.

{
    if (!branch) return;

    for(ssgEntity* i = branch->getKid(0); i != NULL; i = branch->getNextKid())
    {
        if (i->getName())
        { // We found something that might be a wheel
            if (strcmp(i->getName(), "WheelFront.L") == 0)
            {
                m_wheel_front_l = add_transform(dynamic_cast<ssgTransform*>(i));
            }
            else if (strcmp(i->getName(), "WheelFront.R") == 0)
            {
                m_wheel_front_r = add_transform(dynamic_cast<ssgTransform*>(i));
            }
            else if (strcmp(i->getName(), "WheelRear.L") == 0)
            {
                m_wheel_rear_l = add_transform(dynamic_cast<ssgTransform*>(i));
            }
            else if (strcmp(i->getName(), "WheelRear.R") == 0)
            {
                m_wheel_rear_r = add_transform(dynamic_cast<ssgTransform*>(i));
            }
            else
            {
                // Wasn't a wheel, continue searching
                load_wheels(dynamic_cast<ssgBranch*>(i));
            }
        }
        else
        { // Can't be a wheel,continue searching
            load_wheels(dynamic_cast<ssgBranch*>(i));
        }
    }   // for i
}   // load_wheels

Here is the call graph for this function:

Here is the caller graph for this function:

void Kart::loadData ( ) [inherited]

Definition at line 972 of file kart.cpp.

{
    float r [ 2 ] = { -10.0f, 100.0f } ;

    m_smokepuff = new ssgSimpleState ();
    m_smokepuff->setTexture(material_manager->getMaterial("smoke.rgb")->getState()->getTexture());
    m_smokepuff -> setTranslucent    () ;
    m_smokepuff -> enable            ( GL_TEXTURE_2D ) ;
    m_smokepuff -> setShadeModel     ( GL_SMOOTH ) ;
    m_smokepuff -> enable            ( GL_CULL_FACE ) ;
    m_smokepuff -> enable            ( GL_BLEND ) ;
    m_smokepuff -> enable            ( GL_LIGHTING ) ;
    m_smokepuff -> setColourMaterial ( GL_EMISSION ) ;
    m_smokepuff -> setMaterial       ( GL_AMBIENT, 0, 0, 0, 1 ) ;
    m_smokepuff -> setMaterial       ( GL_DIFFUSE, 0, 0, 0, 1 ) ;
    m_smokepuff -> setMaterial       ( GL_SPECULAR, 0, 0, 0, 1 ) ;
    m_smokepuff -> setShininess      (  0 ) ;

    ssgEntity *obj = m_kart_properties->getModel();
    createPhysics(obj);

    load_wheels(dynamic_cast<ssgBranch*>(obj));

    // Optimize the model, this can't be done while loading the model
    // because it seems that it removes the name of the wheels or something
    // else needed to load the wheels as a separate object.
    ssgFlatten(obj);

    createDisplayLists(obj);  // create all display lists
    ssgRangeSelector *lod = new ssgRangeSelector ;

    lod -> addKid ( obj ) ;
    lod -> setRanges ( r, 2 ) ;

    this-> getModelTransform() -> addKid ( lod ) ;

    // Attach Particle System
    //JH  sgCoord pipe_pos = {{0, 0, .3}, {0, 0, 0}} ;
    m_smoke_system = new Smoke(this, 50, 100.0f, true, 0.35f, 1000);
    m_smoke_system -> init(5);
    //JH      m_smoke_system -> setState (getMaterial ("smoke.png")-> getState() );
    //m_smoke_system -> setState ( m_smokepuff ) ;
    //      m_exhaust_pipe = new ssgTransform (&pipe_pos);
    //      m_exhaust_pipe -> addKid (m_smoke_system) ;
    //      comp_model-> addKid (m_exhaust_pipe) ;

    // 
    m_skidmark_left  = new SkidMark(/* angle sign */ -1);
    m_skidmark_right = new SkidMark(/* angle sign */  1);

    m_shadow = createShadow(m_kart_properties->getShadowFile(), -1, 1, -1, 1);
    m_shadow->ref();
    m_model_transform->addKid ( m_shadow );
}   // loadData

Here is the call graph for this function:

Here is the caller graph for this function:

float DefaultRobot::normalize_angle ( float  angle) [inline, private]

Definition at line 797 of file default_robot.cpp.

{
    while( angle > 360.0 ) angle -= 360;
    while( angle < -360.0 ) angle += 360;

    if( angle > 180.0 ) angle -= 360.0;
    else if( angle < -180.0 ) angle += 360.0;

    return angle;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Kart::placeModel ( ) [virtual, inherited]

Reimplemented from Moveable.

Definition at line 1028 of file kart.cpp.

{
    sgMat4 wheel_front;
    sgMat4 wheel_steer;
    sgMat4 wheel_rot;

    sgMakeRotMat4( wheel_rot, 0, RAD_TO_DEGREE(-m_wheel_rotation), 0);
    sgMakeRotMat4( wheel_steer, m_controls.lr * 30.0f , 0, 0);

    sgMultMat4(wheel_front, wheel_steer, wheel_rot);

    if (m_wheel_front_l) m_wheel_front_l->setTransform(wheel_front);
    if (m_wheel_front_r) m_wheel_front_r->setTransform(wheel_front);

    if (m_wheel_rear_l) m_wheel_rear_l->setTransform(wheel_rot);
    if (m_wheel_rear_r) m_wheel_rear_r->setTransform(wheel_rot);

    // Only transfer the bullet data to the plib tree if no history is being
    // replayed.
    if(!user_config->m_replay_history)
    {
        float m[4][4];
        getTrans().getOpenGLMatrix((float*)&m);
        
        //printf(" is %f %f %f\n",t.getOrigin().x(),t.getOrigin().y(),t.getOrigin().z());
        // Transfer the new position and hpr to m_curr_pos
        sgSetCoord(&m_curr_pos, m);
    }
    sgCoord c ;
    sgCopyCoord ( &c, &m_curr_pos );
    const float CENTER_SHIFT  = getGravityCenterShift();
    const float offset_pitch  = m_wheelie_angle;
    const float offset_z      = 0.3f*fabs(sin(m_wheelie_angle*SG_DEGREES_TO_RADIANS))
                              - (0.5f-CENTER_SHIFT)*getKartHeight();
    
    m_curr_pos.xyz[2] += offset_z;
    m_curr_pos.hpr[1] += offset_pitch;
    Moveable::placeModel();
    m_curr_pos.xyz[2] -= offset_z;
    m_curr_pos.hpr[1] -= offset_pitch;
}   // placeModel

Here is the call graph for this function:

Here is the caller graph for this function:

void Kart::processSkidMarks ( ) [inherited]

Definition at line 896 of file kart.cpp.

{
    // FIXME: disable skidmarks for now, they currently look ugly, and are
    //        sometimes hovering in the air
    return;
    assert(m_skidmark_left);
    assert(m_skidmark_right);
    const float threshold = 0.3f;
    const float ANGLE     = 43.0f;
    const float LENGTH    = 0.57f;
    bool skid_front = m_vehicle->getWheelInfo(0).m_skidInfo < threshold ||
                      m_vehicle->getWheelInfo(1).m_skidInfo < threshold;
    bool skid_rear  = m_vehicle->getWheelInfo(2).m_skidInfo < threshold ||
                      m_vehicle->getWheelInfo(3).m_skidInfo < threshold;
    if(skid_rear || skid_front)
    {
        if(isOnGround())
        {
            m_skidmark_left ->add(*getCoord(),  ANGLE, LENGTH);
            m_skidmark_right->add(*getCoord(),  ANGLE, LENGTH);            
        }
        else
        {   // not on ground
            m_skidmark_left->addBreak(*getCoord(),  ANGLE, LENGTH);
            m_skidmark_right->addBreak(*getCoord(), ANGLE, LENGTH);
        }   // on ground
    }
    else
    {   // !skid_rear && !skid_front    
        if(m_skidmark_left->wasSkidMarking())
            m_skidmark_left->addBreak(*getCoord(),  ANGLE, LENGTH);

        if(m_skidmark_right->wasSkidMarking())
            m_skidmark_right->addBreak(*getCoord(), ANGLE, LENGTH);
    }
}   // processSkidMarks

Here is the call graph for this function:

Here is the caller graph for this function:

bool Kart::raceIsFinished ( ) const [inline, inherited]

Definition at line 147 of file kart.hpp.

{ return m_finished_race;       }

Here is the caller graph for this function:

void Moveable::ReadHistory ( char *  s,
int  kartNumber,
int  indx 
) [inherited]

Definition at line 193 of file moveable.cpp.

{
    int k;
    sscanf(s, "Kart %d: v=%f,%f,%f,%f,%f,%f, p=%f,%f,%f,%f,%f,%f", &k,
           m_history_velocity[indx].xyz+0,
           m_history_velocity[indx].xyz+1,
           m_history_velocity[indx].xyz+2,
           m_history_velocity[indx].hpr+0,
           m_history_velocity[indx].hpr+1,
           m_history_velocity[indx].hpr+2,
           m_history_position[indx].xyz+0,
           m_history_position[indx].xyz+1,
           m_history_position[indx].xyz+2,
           m_history_position[indx].hpr+0,
           m_history_position[indx].hpr+1,
           m_history_position[indx].hpr+2);
    if(k!=kartNumber)
    {
        fprintf(stderr,"WARNING: tried reading data for kart %d, found:\n",
                kartNumber);
        fprintf(stderr,"%s\n",s);
        exit(-2);
    }
}   // ReadHistory

Here is the caller graph for this function:

void DefaultRobot::reset ( ) [virtual]

Reimplemented from Kart.

Definition at line 773 of file default_robot.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void Kart::resetBrakes ( ) [inherited]

This function is called when the race starts.

Up to then all brakes are braking (to avoid the kart from rolling downhill), but they need to be set to zero (otherwise the brakes will be braking whenever no engine force is set, i.e. the kart is not accelerating).

Definition at line 752 of file kart.cpp.

{
    for(int i=0; i<4; i++) m_vehicle->setBrake(0.0f, i);
}   // resetBrakes

Here is the call graph for this function:

void Kart::setAttachmentType ( attachmentType  t,
float  time_left = 0.0f,
Kart k = NULL 
) [inline, inherited]

Definition at line 136 of file kart.hpp.

                                          { m_attachment.set(t, time_left, k);   }

Here is the call graph for this function:

Here is the caller graph for this function:

void Kart::setCollectable ( CollectableType  t,
int  n 
) [inline, inherited]

Definition at line 128 of file kart.hpp.

                                          { m_collectable.set(t, n);             }

Here is the call graph for this function:

Here is the caller graph for this function:

void Moveable::setCoord ( sgCoord *  pos) [inline, inherited]

Definition at line 70 of file moveable.hpp.

{sgCopyCoord ( &m_curr_pos,pos);    }
void Kart::setFinishingState ( float  time) [inherited]

Definition at line 1070 of file kart.cpp.

{
    m_finished_race = true;
    m_finish_time   = time;
}   // setFinishingState
void Kart::setKartProperties ( const KartProperties kp) [inline, inherited]

Definition at line 124 of file kart.hpp.

virtual void Kart::setPosition ( int  p) [inline, virtual, inherited]

Reimplemented in PlayerKart.

Definition at line 130 of file kart.hpp.

                                          { m_race_position = p;                 }
void Kart::setTimeAtLap ( float  t) [inline, inherited]

Definition at line 186 of file kart.hpp.

Here is the caller graph for this function:

void Moveable::setTrans ( btTransform t) [inline, inherited]

Definition at line 81 of file moveable.hpp.

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void Moveable::setVelocity ( const btVector3 v) [inline, virtual, inherited]

Reimplemented in Homing.

Definition at line 65 of file moveable.hpp.

Here is the call graph for this function:

Here is the caller graph for this function:

float DefaultRobot::steer_to_angle ( const size_t  SECTOR,
const float  ANGLE 
) [private]

Definition at line 531 of file default_robot.cpp.

{
    float angle = world->m_track->m_angle[SECTOR];

    //Desired angle minus current angle equals how many angles to turn
    float steer_angle = angle - m_curr_pos.hpr[0];

    steer_angle += ANGLE;
    steer_angle = normalize_angle( steer_angle );


    return steer_angle;
}

Here is the call graph for this function:

Here is the caller graph for this function:

float DefaultRobot::steer_to_point ( const sgVec2  POINT) [private]

Definition at line 546 of file default_robot.cpp.

{
    const SGfloat ADJACENT_LINE = POINT[0] - m_curr_pos.xyz[0];
    const SGfloat OPPOSITE_LINE = POINT[1] - m_curr_pos.xyz[1];
    SGfloat theta;

    //Protection from division by zero
    if( ADJACENT_LINE > 0.0000001 || ADJACENT_LINE < -0.0000001 )
    {
        theta = sgATan( OPPOSITE_LINE / ADJACENT_LINE );
    }
    else theta = 0;

    //The real value depends on the side of the track that the kart is
    theta += ADJACENT_LINE < 0.0f ? 90.0f : -90.0f;

    float steer_angle = theta - getCoord()->hpr[0];
    steer_angle = normalize_angle( steer_angle );

    return steer_angle;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void TerrainInfo::update ( const btVector3 pos) [virtual, inherited]

Definition at line 34 of file terrain_info.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void DefaultRobot::update ( float  delta) [virtual]

Reimplemented from Kart.

Definition at line 90 of file default_robot.cpp.

{
    if( world->isStartPhase())
    {
        handle_race_start();
        AutoKart::update( delta );
        return;
    }

    /*Get information that is needed by more than 1 of the handling funcs*/
    //Detect if we are going to crash with the track and/or kart
    int steps = 0;

    // This should not happen (anymore :) ), but it keeps the game running
    // in case that m_future_sector becomes undefined.
    if(m_future_sector == Track::UNKNOWN_SECTOR )
    {
#ifdef DEBUG
        fprintf(stderr,"DefaultRobot: m_future_sector is undefined.\n");
        fprintf(stderr,"This shouldn't happen, but can be ignored.\n");
#endif
        forceRescue();
        m_future_sector = 0;
    }
    else
    {
        steps = calc_steps();
    }

    check_crashes( steps, m_curr_pos.xyz );
    find_curve();

    /*Response handling functions*/
    handle_acceleration( delta );
    handle_steering();
    handle_items( delta, steps );
    handle_rescue( delta );
    handle_wheelie( steps );
    handle_braking();
    //TODO:handle jumping

    /*And obviously general kart stuff*/
    AutoKart::update( delta );
}   // update

Here is the call graph for this function:

void Kart::updateBulletPhysics ( float  dt) [inherited]
void Kart::updatePhysics ( float  dt) [inherited]

Definition at line 757 of file kart.cpp.

{
    float engine_power = getActualWheelForce() + handleWheelie(dt);
    if(m_attachment.getType()==ATTACH_PARACHUTE) engine_power*=0.2f;

    if(m_controls.accel)
    {   // accelerating
        m_vehicle->applyEngineForce(engine_power, 2);
        m_vehicle->applyEngineForce(engine_power, 3);
    }
    else
    {   // not accelerating
        if(m_controls.brake)
        {   // braking or moving backwards
            if(m_speed > 0.f)
            {   // going forward, apply brake force
                m_vehicle->applyEngineForce(-getBrakeFactor()*engine_power, 2);
                m_vehicle->applyEngineForce(-getBrakeFactor()*engine_power, 3);
            }
            else
            {   // going backward, apply reverse gear ratio
                if ( fabs(m_speed) <  m_max_speed*m_max_speed_reverse_ratio )
                {
                    m_vehicle->applyEngineForce(-engine_power*m_controls.brake, 2);
                    m_vehicle->applyEngineForce(-engine_power*m_controls.brake, 3);
                }
                else
                {
                    m_vehicle->applyEngineForce(0.f, 2);
                    m_vehicle->applyEngineForce(0.f, 3);
                }
            }
        }
        else
        {   // lift the foot from throttle, brakes with 10% engine_power
            m_vehicle->applyEngineForce(-m_controls.accel*engine_power*0.1f, 2);
            m_vehicle->applyEngineForce(-m_controls.accel*engine_power*0.1f, 3);
        }
    }

    if(isOnGround() && m_controls.jump)
    { 
      //Vector3 impulse(0.0f, 0.0f, 10.0f);
      //        getVehicle()->getRigidBody()->applyCentralImpulse(impulse);
        btVector3 velocity         = m_body->getLinearVelocity();
        velocity.setZ( m_kart_properties->getJumpVelocity() );

        getBody()->setLinearVelocity( velocity );

    }
    if(m_wheelie_angle<=0.0f)
    {
        const float steering = DEGREE_TO_RAD(getMaxSteerAngle()) * m_controls.lr;
        m_vehicle->setSteeringValue(steering, 0);
        m_vehicle->setSteeringValue(steering, 1);
    } 
    else 
    {
        m_vehicle->setSteeringValue(0.0f, 0);
        m_vehicle->setSteeringValue(0.0f, 1);
    }

    //store current velocity
    m_speed = getVehicle()->getRigidBody()->getLinearVelocity().length();

    // calculate direction of m_speed
    const btTransform& chassisTrans = getVehicle()->getChassisWorldTransform();
    btVector3 forwardW (
               chassisTrans.getBasis()[0][1],
               chassisTrans.getBasis()[1][1],
               chassisTrans.getBasis()[2][1]);

    if (forwardW.dot(getVehicle()->getRigidBody()->getLinearVelocity()) < btScalar(0.))
        m_speed *= -1.f;

    //cap at maximum velocity
    const float max_speed = m_kart_properties->getMaximumSpeed();
    if ( m_speed >  max_speed )
    {
        const float velocity_ratio = max_speed/m_speed;
        m_speed                    = max_speed;
        btVector3 velocity         = m_body->getLinearVelocity();

        velocity.setY( velocity.getY() * velocity_ratio );
        velocity.setX( velocity.getX() * velocity_ratio );

        getVehicle()->getRigidBody()->setLinearVelocity( velocity );

    }
    //at low velocity, forces on kart push it back and forth so we ignore this
    if(fabsf(m_speed) < 0.2f) // quick'n'dirty workaround for bug 1776883
         m_speed = 0;
}   // updatePhysics

Here is the call graph for this function:

Here is the caller graph for this function:

void Moveable::WriteHistory ( char *  s,
int  kartNumber,
int  indx 
) [inherited]

Definition at line 175 of file moveable.cpp.

{
    sprintf(s, "Kart %d: v=%f,%f,%f,%f,%f,%f, p=%f,%f,%f,%f,%f,%f", kartNumber,
            m_history_velocity[indx].xyz[0],
            m_history_velocity[indx].xyz[1],
            m_history_velocity[indx].xyz[2],
            m_history_velocity[indx].hpr[0],
            m_history_velocity[indx].hpr[1],
            m_history_velocity[indx].hpr[2],
            m_history_position[indx].xyz[0],
            m_history_position[indx].xyz[1],
            m_history_position[indx].xyz[2],
            m_history_position[indx].hpr[0],
            m_history_position[indx].hpr[1],
            m_history_position[indx].hpr[2]);
}   // WriteHistory

Here is the caller graph for this function:


Member Data Documentation

Attachment Kart::m_attachment [protected, inherited]

Definition at line 56 of file kart.hpp.

btRigidBody* Moveable::m_body [protected, inherited]

Definition at line 53 of file moveable.hpp.

Collectable Kart::m_collectable [protected, inherited]

Definition at line 57 of file kart.hpp.

int Moveable::m_collided [protected, inherited]

Definition at line 47 of file moveable.hpp.

KartControl Kart::m_controls [protected, inherited]

Definition at line 62 of file kart.hpp.

float DefaultRobot::m_crash_time [private]

Definition at line 81 of file default_robot.hpp.

int Moveable::m_crashed [protected, inherited]

Definition at line 48 of file moveable.hpp.

sgCoord Moveable::m_curr_pos [protected, inherited]

Definition at line 42 of file moveable.hpp.

sgVec3 Kart::m_curr_track_coords [protected, inherited]

Definition at line 66 of file kart.hpp.

float DefaultRobot::m_curve_angle [private]

Definition at line 94 of file default_robot.hpp.

Definition at line 93 of file default_robot.hpp.

Definition at line 68 of file default_robot.hpp.

char Kart::m_fastest_lap_message[255] [protected, inherited]

Definition at line 72 of file kart.hpp.

int Moveable::m_first_time [protected, inherited]

Definition at line 50 of file moveable.hpp.

Definition at line 85 of file default_robot.hpp.

Definition at line 84 of file default_robot.hpp.

int Kart::m_grid_position [protected, inherited]

Definition at line 59 of file kart.hpp.

sgCoord* Moveable::m_history_position [protected, inherited]

Definition at line 52 of file moveable.hpp.

sgCoord* Moveable::m_history_velocity [protected, inherited]

Definition at line 51 of file moveable.hpp.

int Kart::m_initial_position [protected, inherited]

Definition at line 61 of file kart.hpp.

Definition at line 92 of file default_robot.hpp.

Definition at line 76 of file default_robot.hpp.

btCompoundShape Kart::m_kart_chassis [protected, inherited]

Definition at line 78 of file kart.hpp.

const KartProperties* Kart::m_kart_properties [protected, inherited]

Definition at line 110 of file kart.hpp.

float Kart::m_lap_start_time [protected, inherited]

Definition at line 71 of file kart.hpp.

sgVec2 Kart::m_last_track_coords [protected, inherited]

Definition at line 65 of file kart.hpp.

Material* Moveable::m_material_hot [protected, inherited]

Definition at line 44 of file moveable.hpp.

Definition at line 65 of file default_robot.hpp.

float Kart::m_max_speed [protected, inherited]

Definition at line 67 of file kart.hpp.

float Kart::m_max_speed_reverse_ratio [protected, inherited]

Definition at line 68 of file kart.hpp.

Definition at line 56 of file default_robot.hpp.

Definition at line 58 of file default_robot.hpp.

ssgTransform* Moveable::m_model_transform [protected, inherited]

Definition at line 45 of file moveable.hpp.

Definition at line 54 of file moveable.hpp.

sgVec4* Moveable::m_normal_hot [protected, inherited]

Definition at line 43 of file moveable.hpp.

bool Kart::m_on_road [protected, inherited]

Definition at line 54 of file kart.hpp.

int Kart::m_race_position [protected, inherited]

Definition at line 60 of file kart.hpp.

float Kart::m_rescue_pitch [protected, inherited]

Definition at line 109 of file kart.hpp.

float Kart::m_rescue_roll [protected, inherited]

Definition at line 109 of file kart.hpp.

sgCoord Moveable::m_reset_pos [protected, inherited]

Definition at line 41 of file moveable.hpp.

int DefaultRobot::m_sector [private]

Definition at line 127 of file default_robot.hpp.

ssgTransform* Moveable::m_shadow [protected, inherited]

Definition at line 46 of file moveable.hpp.

int Kart::m_shortcut_sector [protected, inherited]

Definition at line 74 of file kart.hpp.

Definition at line 98 of file default_robot.hpp.

sgVec3 Moveable::m_surface_avoidance_vector [protected, inherited]

Definition at line 49 of file moveable.hpp.

Definition at line 83 of file default_robot.hpp.

Definition at line 96 of file default_robot.hpp.

Definition at line 87 of file default_robot.hpp.

int Kart::m_track_sector [protected, inherited]

Definition at line 63 of file kart.hpp.

btTransform Moveable::m_transform [protected, inherited]

Definition at line 55 of file moveable.hpp.

Definition at line 77 of file kart.hpp.

Definition at line 81 of file kart.hpp.

Definition at line 72 of file default_robot.hpp.

UserPointer Moveable::m_user_pointer [protected, inherited]

Definition at line 40 of file moveable.hpp.

btRaycastVehicle* Kart::m_vehicle [protected, inherited]

Definition at line 80 of file kart.hpp.

Definition at line 79 of file kart.hpp.

Definition at line 62 of file default_robot.hpp.

float Kart::m_wheelie_angle [protected, inherited]

Definition at line 69 of file kart.hpp.

Definition at line 73 of file default_robot.hpp.

float Kart::m_zipper_time_left [protected, inherited]

Definition at line 70 of file kart.hpp.


The documentation for this class was generated from the following files: