Back to index

supertuxkart  0.5+dfsg1
attachment_manager.cpp
Go to the documentation of this file.
00001 //  $Id: attachment_manager.cpp 808 2006-10-03 20:17:37Z coz $
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 #include "attachment_manager.hpp"
00021 #include "file_manager.hpp"
00022 #include "loader.hpp"
00023 
00024 AttachmentManager *attachment_manager = 0;
00025 
00026 struct  initAttachmentType {attachmentType attachment; const char *file;};
00027 
00028 /* Some explanations to the attachments:
00029    Parachute: This will increase the air friction, reducing the maximum speed.
00030               It will not have too much of an effect on slow speeds, since air
00031               friction only becomes important at higher speeds.
00032    Anvil:     It increases the weight of the kart.But this will NOT have any
00033               effect on karts already driving at highest speed: the accelerating
00034        force is independent of the mass, so it is 0 at highest speed 
00035        (engine force = air- plus system-force) and only this value gets
00036        divided by the mass later --> at highest speed there would be no 
00037        effect when the mass is changed, only at lower speeds the acting 
00038        acceleration will be lower.Reducing the power slows the kart down,
00039        but doesn't give the feeling of a sudden weight increase. 
00040        Therefore the anvil will reduce by a certain factor (see physics
00041        parameters) once when it is attached. Together with the mass 
00042        increase (lower acceleration) it's sufficient negative.
00043 */
00044 
00045 initAttachmentType iat[]=
00046 {
00047     {ATTACH_PARACHUTE,   "parachute.ac"},
00048     {ATTACH_BOMB,        "bomb.ac"},
00049     {ATTACH_ANVIL,       "anvil.ac"},
00050     {ATTACH_TINYTUX,     "tinytux_magnet.ac"},
00051     {ATTACH_MAX,         ""},
00052 };
00053 
00054 //-----------------------------------------------------------------------------
00055 void AttachmentManager::removeTextures()
00056 {
00057     for(int i=0; iat[i].attachment!=ATTACH_MAX; i++)
00058     {
00059         ssgDeRefDelete(m_attachments[iat[i].attachment]);
00060     }   // for
00061     callback_manager->clear(CB_ATTACHMENT);
00062 }   // removeTextures
00063 
00064 //-----------------------------------------------------------------------------
00065 void AttachmentManager::loadModels()
00066 {
00067     for(int i=0; iat[i].attachment!=ATTACH_MAX; i++)
00068     {
00069         m_attachments[iat[i].attachment]=loader->load(iat[i].file, CB_ATTACHMENT);
00070         m_attachments[iat[i].attachment]->ref();
00071     }   // for
00072 }   // reInit
00073