src/weapon/parachute.cpp

Go to the documentation of this file.
00001 /******************************************************************************
00002  *  Wormux is a convivial mass murder game.
00003  *  Copyright (C) 2001-2004 Lawrence Azzoug.
00004  *
00005  *  This program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2 of the License, or
00008  *  (at your option) any later version.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
00018  ******************************************************************************
00019  * Parachute !
00020  *****************************************************************************/
00021 
00022 #include "parachute.h"
00023 #include "explosion.h"
00024 #include "../game/game.h"
00025 #include "../game/game_mode.h"
00026 #include "../game/game_loop.h"
00027 #include "../interface/game_msg.h"
00028 #include "../object/physical_obj.h"
00029 #include "../sound/jukebox.h"
00030 #include "../team/teams_list.h"
00031 #include "../tool/i18n.h"
00032 
00033 Parachute::Parachute() : Weapon(WEAPON_PARACHUTE, "parachute", new ParachuteConfig(), NEVER_VISIBLE)
00034 {
00035   m_name = _("Parachute");
00036   m_initial_nb_ammo = 2 ;
00037   use_unit_on_first_shoot = false;
00038 
00039   image = resource_manager.LoadSprite(weapons_res_profile,"parachute_sprite");
00040 }
00041 
00042 void Parachute::p_Select()
00043 {
00044   m_is_active = true ;
00045   open = false ;
00046   closing = false ;
00047   image->animation.SetShowOnFinish(SpriteAnimation::show_last_frame);
00048 }
00049 
00050 void Parachute::p_Deselect()
00051 {
00052   ActiveCharacter().ResetConstants();
00053   m_is_active = false;
00054 }
00055 
00056 bool Parachute::p_Shoot()
00057 {
00058   GameMessages::GetInstance()->Add(_("Parachute is activated automatically."));
00059   return false;
00060 }
00061 
00062 void Parachute::Draw()
00063 {
00064   if (open)
00065     {
00066       image->Update();
00067       image->Draw(ActiveCharacter().GetHandPosition() - Point2i(image->GetWidth()/2,image->GetHeight()));
00068     }
00069 }
00070 
00071 void Parachute::Refresh()
00072 {
00073   double speed;
00074   double angle;
00075 
00076   ActiveCharacter().GetSpeed(speed, angle);
00077 
00078   if (ActiveCharacter().FootsInVacuum() && speed != 0.0)
00079     {
00080       if (!open && (speed > GameMode::GetInstance()->safe_fall))
00081       {
00082         if (EnoughAmmo())
00083         {
00084           UseAmmo();
00085           ActiveCharacter().SetAirResistFactor(cfg().air_resist_factor);
00086           ActiveCharacter().SetWindFactor(cfg().wind_factor);
00087           open = true ;
00088           image->animation.SetPlayBackward(false);
00089           image->Start();
00090           ActiveCharacter().SetSpeedXY(Point2d(0,0));
00091           ActiveCharacter().SetMovement("parachute");
00092         }
00093       }
00094     }
00095   else
00096     {
00097       /* We are on the ground */
00098       if (open)
00099       {
00100         /* The parachute is opened */
00101         if (!closing)
00102         {
00103           /* We have just hit the ground. Start closing animation */
00104           image->animation.SetPlayBackward(true);
00105           image->animation.SetShowOnFinish(SpriteAnimation::show_blank);
00106           image->Start();
00107           closing = true ;
00108         }
00109         else
00110         {/* The parachute is closing */
00111           if (image->IsFinished())
00112           {
00113                   /* The animation is finished...
00114             We are done with the parachute */
00115             open = false ;
00116             closing = false ;
00117             UseAmmoUnit();
00118           }
00119         }
00120       }
00121     }
00122 }
00123 
00124 void Parachute::SignalTurnEnd()
00125 {
00126   p_Deselect();
00127 }
00128 
00129 ParachuteConfig& Parachute::cfg() {
00130   return static_cast<ParachuteConfig&>(*extra_params);
00131 }
00132 
00133 ParachuteConfig::ParachuteConfig(){ 
00134   wind_factor = 10.0;
00135   air_resist_factor = 140.0 ;
00136 }
00137 
00138 void ParachuteConfig::LoadXml(xmlpp::Element *elem){
00139   WeaponConfig::LoadXml(elem);
00140   XmlReader::ReadDouble(elem, "wind_factor", wind_factor);
00141   XmlReader::ReadDouble(elem, "air_resist_factor", air_resist_factor);
00142 }

Generated on Mon Jan 1 13:11:00 2007 for Wormux by  doxygen 1.4.7