Back to index

supertuxkart  0.5+dfsg1
Public Member Functions | Private Attributes
Attachment Class Reference

#include <attachment.hpp>

Collaboration diagram for Attachment:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Attachment (Kart *_kart)
 ~Attachment ()
void set (attachmentType _type, float time, Kart *previous_kart=NULL)
void set (attachmentType _type)
void clear ()
attachmentType getType () const
float getTimeLeft () const
void setTimeLeft (float t)
KartgetPreviousOwner () const
float WeightAdjust () const
float AirResistanceAdjust () const
float SpeedAdjust () const
void hitGreenHerring ()
void update (float dt)
void moveBombFromTo (Kart *from, Kart *to)

Private Attributes

attachmentType m_type
Kartm_kart
float m_time_left
float m_initial_speed
ssgSelector * m_holder
Kartm_previous_owner

Detailed Description

Definition at line 35 of file attachment.hpp.


Constructor & Destructor Documentation

Definition at line 32 of file attachment.cpp.

{
    m_type           = ATTACH_NOTHING;
    m_time_left      = 0.0;
    m_kart           = _kart;
    m_holder         = new ssgSelector();
    m_previous_owner = NULL;
    m_kart->getModelTransform()->addKid(m_holder);

    for(int i=ATTACH_PARACHUTE; i<=ATTACH_TINYTUX; i++)
    {
        ssgEntity *p=attachment_manager->getModel((attachmentType)i);
        m_holder->addKid(p);
    }
    m_holder->select(0);
}   // Attachment

Here is the call graph for this function:

Definition at line 50 of file attachment.cpp.

{
    ssgDeRefDelete(m_holder);
}   // ~Attachment

Member Function Documentation

float Attachment::AirResistanceAdjust ( ) const [inline]

Definition at line 65 of file attachment.hpp.

void Attachment::clear ( ) [inline]

Definition at line 51 of file attachment.hpp.

                                    {
                                      m_type=ATTACH_NOTHING; 
                                      m_time_left=0.0;
                                      m_holder->select(0);
                                    }

Here is the caller graph for this function:

Kart* Attachment::getPreviousOwner ( ) const [inline]

Definition at line 59 of file attachment.hpp.

{ return m_previous_owner; }

Here is the caller graph for this function:

float Attachment::getTimeLeft ( ) const [inline]

Definition at line 57 of file attachment.hpp.

{ return m_time_left;      }

Here is the caller graph for this function:

attachmentType Attachment::getType ( ) const [inline]

Definition at line 56 of file attachment.hpp.

{ return m_type;           }

Here is the caller graph for this function:

Definition at line 65 of file attachment.cpp.

{
    if(user_config->m_profile) return;
    int random_attachment;
    float leftover_time   = 0.0f;
    switch(getType())   // If there already is an attachment, make it worse :)
    {
    case ATTACH_BOMB:  projectile_manager->newExplosion(m_kart->getCoord());
                       // Best solution would probably be to trigger the
                       // explosion, and then to attach a new, random
                       // attachment. Unfortunately, handleExplosion() is not
                       // really severe enough, and forceRescue() attaches
                       // tinytux, so that the new attachment is immediately lost.
                       // m_kart->handleExplosion(m_kart->getCoord()->xyz, true);
                       m_kart->handleExplosion(m_kart->getPos(), /*direct_hit*/ true);
                       clear();
                       random_attachment = rand()%3;
                       break;
    case ATTACH_ANVIL :// if the kart already has an anvil, attach a new anvil, 
                       // and increase the overall time 
                       random_attachment = 2;
                       leftover_time     = m_time_left;
                       break;
    case ATTACH_PARACHUTE:
                       random_attachment = 2;  // anvil
                       leftover_time     = m_time_left;
                       break;
    default:           random_attachment = rand()%3;
    }   // switch

    switch (random_attachment)
    {
    case 0: set( ATTACH_PARACHUTE, stk_config->m_parachute_time+leftover_time);
        m_initial_speed = m_kart->getSpeed();
        // if ( m_kart == m_kart[0] )
        //   sound -> playSfx ( SOUND_SHOOMF ) ;
        break ;
    case 1: set( ATTACH_BOMB, stk_config->m_bomb_time+leftover_time);
        // if ( m_kart == m_kart[0] )
        //   sound -> playSfx ( SOUND_SHOOMF ) ;
        break ;
    case 2: set( ATTACH_ANVIL, stk_config->m_anvil_time+leftover_time);
        // if ( m_kart == m_kart[0] )
        //   sound -> playSfx ( SOUND_SHOOMF ) ;
        // Reduce speed once (see description above), all other changes are
        // handled in Kart::updatePhysics
        m_kart->adjustSpeedWeight(stk_config->m_anvil_speed_factor);
        break ;
    }   // switch rand()%3
}   // hitGreenHerring

Here is the call graph for this function:

Here is the caller graph for this function:

void Attachment::moveBombFromTo ( Kart from,
Kart to 
)

Definition at line 118 of file attachment.cpp.

{
    to->setAttachmentType(ATTACH_BOMB,
                          from->getAttachment()->getTimeLeft()+
                          stk_config->m_bomb_time_increase, from);
    from->getAttachment()->clear();
}   // moveBombFromTo

Here is the call graph for this function:

Here is the caller graph for this function:

void Attachment::set ( attachmentType  _type,
float  time,
Kart previous_kart = NULL 
)

Definition at line 56 of file attachment.cpp.

{
    m_holder->selectStep(_type);
    m_type           = _type;
    m_time_left      = time;
    m_previous_owner = current_kart;
}   // set

Here is the caller graph for this function:

void Attachment::set ( attachmentType  _type) [inline]

Definition at line 50 of file attachment.hpp.

{ set(_type, m_time_left); }
void Attachment::setTimeLeft ( float  t) [inline]

Definition at line 58 of file attachment.hpp.

{ m_time_left = t;         }

Here is the caller graph for this function:

float Attachment::SpeedAdjust ( ) const [inline]

Definition at line 70 of file attachment.hpp.

void Attachment::update ( float  dt)

Definition at line 127 of file attachment.cpp.

{
    if(m_type==ATTACH_NOTHING) return;
    m_time_left -=dt;

    switch (m_type)
    {
    case ATTACH_PARACHUTE: // Partly handled in Kart::updatePhysics
                           // Otherwise: disable if a certain percantage of
                           // initial speed was lost
                           if(m_kart->getSpeed()<=
                               m_initial_speed*stk_config->m_parachute_done_fraction)
                           {
                                   m_time_left = -1;
                           }
                           break;
    case ATTACH_ANVIL:     // handled in Kart::updatePhysics
    case ATTACH_NOTHING:   // Nothing to do, but complete all cases for switch
    case ATTACH_MAX:       break;
    case ATTACH_BOMB:      if(m_time_left<=0.0) 
                           {
                               projectile_manager->newExplosion(m_kart->getCoord());
                               m_kart->handleExplosion(m_kart->getPos(), 
                                                       /*direct_hit*/ true);
                           }
                           break;
    case ATTACH_TINYTUX:   if(m_time_left<=0.0) m_kart->endRescue();
                           break;
    }   // switch

    // Detach attachment if its time is up.
    if ( m_time_left <= 0.0f)
    {
        if(m_type==ATTACH_ANVIL) 
        {
            // Resets the weight, and multiplies the velocity by 1.0, 
            // i.e. no change of velocity.
            m_kart->getAttachment()->clear();
            m_kart->adjustSpeedWeight(1.0f);
        }
        clear();
    }   // if m_time_left<0
}   // update

Here is the call graph for this function:

Here is the caller graph for this function:

float Attachment::WeightAdjust ( ) const [inline]

Definition at line 60 of file attachment.hpp.

Here is the caller graph for this function:


Member Data Documentation

ssgSelector* Attachment::m_holder [private]

Definition at line 42 of file attachment.hpp.

float Attachment::m_initial_speed [private]

Definition at line 41 of file attachment.hpp.

Definition at line 39 of file attachment.hpp.

Definition at line 43 of file attachment.hpp.

float Attachment::m_time_left [private]

Definition at line 40 of file attachment.hpp.

Definition at line 38 of file attachment.hpp.


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