Back to index

supertuxkart  0.5+dfsg1
attachment.hpp
Go to the documentation of this file.
00001 //  $Id: attachment.hpp 2111 2008-05-31 07:04:30Z cosmosninja $
00002 //
00003 //  SuperTuxKart - a fun racing game with go-kart
00004 //  Copyright (C) 2006 Joerg Henrichs
00005 //
00006 //  This program is free software; you can redistribute it and/or
00007 //  modify it under the terms of the GNU General Public License
00008 //  as published by the Free Software Foundation; either version 2
00009 //  of the License, or (at your option) any later version.
00010 //
00011 //  This program is distributed in the hope that it will be useful,
00012 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //  GNU General Public License for more details.
00015 //
00016 //  You should have received a copy of the GNU General Public License
00017 //  along with this program; if not, write to the Free Software
00018 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019 
00020 #ifndef HEADER_ATTACHMENT_H
00021 #define HEADER_ATTACHMENT_H
00022 
00023 #include "stk_config.hpp"
00024 class Kart;
00025 
00026 // Some loop in Attachment.cpp depend on PARACHUTE being the first element,
00027 // and TINYTUX being the last one. So if new elemts are added, make sure
00028 // to add them in between those values.
00029 enum attachmentType { ATTACH_PARACHUTE,
00030                       ATTACH_BOMB,
00031                       ATTACH_ANVIL, ATTACH_TINYTUX,
00032                       ATTACH_MAX, ATTACH_NOTHING};
00033 
00034 
00035 class Attachment
00036 {
00037 private:
00038     attachmentType  m_type;            // attachment type
00039     Kart           *m_kart;            // kart the attachment is attached to
00040     float           m_time_left;       // time left till attachment expires
00041     float           m_initial_speed;   // for parachutes only
00042     ssgSelector    *m_holder;          // where the attachment is put on the kart
00043     Kart           *m_previous_owner;  // used by bombs so that it's not passed
00044                                        // back to previous owner
00045 public:
00046     Attachment(Kart* _kart);
00047     ~Attachment();
00048 
00049     void set (attachmentType _type, float time, Kart *previous_kart=NULL);
00050     void set (attachmentType _type) { set(_type, m_time_left); }
00051     void clear ()                   {
00052                                       m_type=ATTACH_NOTHING; 
00053                                       m_time_left=0.0;
00054                                       m_holder->select(0);
00055                                     }
00056     attachmentType getType () const { return m_type;           }
00057     float getTimeLeft      () const { return m_time_left;      }
00058     void setTimeLeft       (float t){ m_time_left = t;         }
00059     Kart* getPreviousOwner () const { return m_previous_owner; }
00060     float WeightAdjust     () const {
00061                                       return m_type==ATTACH_ANVIL
00062                                           ?stk_config->m_anvil_weight:0.0f;
00063                                     }
00064 
00065     float AirResistanceAdjust () const {
00066                                       return m_type==ATTACH_PARACHUTE
00067                                           ?stk_config->m_parachute_friction:0.0f;
00068                                     }
00069 
00070     float SpeedAdjust () const      {
00071                                       return m_type==ATTACH_ANVIL
00072                                           ?stk_config->m_anvil_speed_factor:1.0f;
00073                                     }
00074     void  hitGreenHerring();
00075     void  update (float dt);
00076     void  moveBombFromTo(Kart *from, Kart *to);
00077 };
00078 
00079 #endif