Back to index

supertuxkart  0.5+dfsg1
Public Member Functions | Protected Attributes
Collectable Class Reference

#include <collectable.hpp>

Collaboration diagram for Collectable:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Collectable (Kart *kart_)
void set (CollectableType _type, int n=1)
void reset ()
int getNum () const
CollectableType getType () const
void hitRedHerring (int n)
MaterialgetIcon ()
void use ()

Protected Attributes

Kartm_owner
CollectableType m_type
int m_number

Detailed Description

Definition at line 29 of file collectable.hpp.


Constructor & Destructor Documentation

Definition at line 30 of file collectable.cpp.

{
    m_owner  = kart_;
    reset();
}   // Collectable

Here is the call graph for this function:


Member Function Documentation

Definition at line 64 of file collectable.cpp.

{
    // Check if it's one of the types which have a separate
    // data file which includes the icon:
    return collectable_manager->getIcon(m_type);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int Collectable::getNum ( ) const [inline]

Definition at line 40 of file collectable.hpp.

{return m_number;}

Here is the caller graph for this function:

Definition at line 41 of file collectable.hpp.

{return m_type;  }

Here is the caller graph for this function:

void Collectable::hitRedHerring ( int  n)

Definition at line 146 of file collectable.cpp.

{
    //The probabilities of getting the anvil or the parachute increase
    //depending on how bad the owner's position is. For the first
    //driver the posibility is none, for the last player is 15 %.

    if(m_owner->getPosition() != 1 && m_type == COLLECT_NOTHING)
    {
        const int SPECIAL_PROB = (int)(15.0 / ((float)world->getCurrentNumKarts() /
                                         (float)m_owner->getPosition()));
        const int RAND_NUM = rand()%100;
        if(RAND_NUM <= SPECIAL_PROB)
        {
            //If the driver in the first position has finished, give the driver
            //the parachute.
            for(unsigned int i=0; i < race_manager->getNumKarts(); ++i)
            {
                Kart *kart = world->getKart(i);
                if(kart->isEliminated() || kart == m_owner) continue;
                if(kart->getPosition() == 1 && kart->raceIsFinished())
                {
                    m_type = COLLECT_PARACHUTE;
                    m_number = 1;
                    return;
                }
            }

            m_type = rand()%(2) == 0 ? COLLECT_ANVIL : COLLECT_PARACHUTE;
            m_number = 1;
            return;
        }
    }

    //rand() is moduled by COLLECT_MAX - 1 - 2 because because we have to
    //exclude the anvil and the parachute, but later we have to add 1 to prevent
    //having a value of 0 since that isn't a valid collectable.
    CollectableType newC;
    if(!user_config->m_profile)
    {
        newC = (CollectableType)(rand()%(COLLECT_MAX - 1 - 2) + 1);
    }
    else
      {   // for now: no collectables when profiling
        return;
        // No random effects when profiling!
        static int simpleCounter=-1;
        simpleCounter++;
        newC = (CollectableType)(simpleCounter%(COLLECT_MAX - 1 - 2) + 1);
    }
    if(m_type==COLLECT_NOTHING)
    {
        m_type=newC;
        m_number = n;
    }
    else if(newC==m_type)
    {
        m_number+=n;
        if(m_number > MAX_COLLECTABLES) m_number = MAX_COLLECTABLES;
    }
    // Ignore new collectable if it is different from the current one
}   // hitRedHerring

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 37 of file collectable.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void Collectable::set ( CollectableType  _type,
int  n = 1 
)

Definition at line 52 of file collectable.cpp.

{
    if (m_type==type)
    {
        m_number+=n;
        return;
    }
    m_type=type;
    m_number=n;
}  // set

Here is the caller graph for this function:

void Collectable::use ( )

Definition at line 72 of file collectable.cpp.

{
    m_number--;
    switch (m_type)
    {
    case COLLECT_ZIPPER:   m_owner->handleZipper();
        break ;
    case COLLECT_HOMING:
    case COLLECT_SPARK:
    case COLLECT_MISSILE:
        if(m_owner->isPlayerKart())
            sound_manager->playSfx(SOUND_SHOT);

        projectile_manager->newProjectile(m_owner, m_type);
        break ;

    case COLLECT_ANVIL:
        //Attach an anvil(twice as good as the one given
        //by the bananas) to the kart in the 1st position.
        for(unsigned int i = 0 ; i < race_manager->getNumKarts(); ++i)
        {
            Kart *kart=world->getKart(i);
            if(kart->isEliminated()) continue;
            if(kart == m_owner) continue;
            if(kart->getPosition() == 1)
            {
                kart->attach(ATTACH_ANVIL, stk_config->m_anvil_time);
                kart->adjustSpeedWeight(stk_config->m_anvil_speed_factor*0.5f);

                if(kart->isPlayerKart())
                    sound_manager->playSfx(SOUND_USE_ANVIL);
                break;
            }
        }

        break;

    case COLLECT_PARACHUTE:
        {
            bool player_affected = false;
            //Attach a parachutte(that last as twice as the
            //one from the bananas) to all the karts that
            //are in front of this one.
            for(unsigned int i = 0 ; i < race_manager->getNumKarts(); ++i)
            {
                Kart *kart=world->getKart(i);
                if(kart->isEliminated() || kart== m_owner) continue;
                if(m_owner->getPosition() > kart->getPosition())
                {
                    kart->attach(ATTACH_PARACHUTE, stk_config->m_parachute_time_other);

                    if(kart->isPlayerKart())
                        player_affected = true;
                }

            }

            if(player_affected)
                sound_manager->playSfx(SOUND_USE_PARACHUTE);
        }
        break;

    case COLLECT_NOTHING:
    default :              break ;
    }

    if ( m_number <= 0 )
    {
        m_number = 0;
        m_type   = COLLECT_NOTHING;
    }
}   // use

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

int Collectable::m_number [protected]

Definition at line 34 of file collectable.hpp.

Kart* Collectable::m_owner [protected]

Definition at line 32 of file collectable.hpp.

Definition at line 33 of file collectable.hpp.


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