src/weapon/gnu.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  * Weapon gnu : a gnu jump in (more or less) random directions and explodes
00020  *****************************************************************************/
00021 
00022 #include "gnu.h"
00023 #include <sstream>
00024 #include "explosion.h"
00025 #include "../game/config.h"
00026 #include "../game/time.h"
00027 #include "../graphic/video.h"
00028 #include "../interface/game_msg.h"
00029 #include "../map/camera.h"
00030 #include "../object/objects_list.h"
00031 #include "../sound/jukebox.h"
00032 #include "../team/teams_list.h"
00033 #include "../tool/math_tools.h"
00034 #include "../tool/i18n.h"
00035 #include "../network/randomsync.h"
00036 
00037 Gnu::Gnu(ExplosiveWeaponConfig& cfg,
00038          WeaponLauncher * p_launcher) :
00039   WeaponProjectile("gnu", cfg, p_launcher)
00040 {
00041   explode_with_collision = false;
00042 }
00043 
00044 void Gnu::Shoot (double strength)
00045 {
00046   WeaponProjectile::Shoot(strength);
00047 
00048   save_x=GetX();
00049   save_y=GetY();
00050 
00051   double angle = ActiveCharacter().GetFiringAngle();
00052 
00053   if(angle<M_PI/2 && angle>-M_PI/2)
00054     m_sens = 1;
00055   else
00056     m_sens = -1;
00057 }
00058 
00059 void Gnu::Refresh()
00060 {
00061   WeaponProjectile::Refresh();
00062 
00063   double norme, angle;
00064   //When we hit the ground, jump !
00065   if(!IsMoving()&& !FootsInVacuum())
00066   {
00067     //If the GNU is stuck in ground -> change direction
00068     int x = GetX();
00069     int y = GetY();
00070     if(x==save_x && y==save_y)
00071       m_sens = - m_sens;
00072     save_x = x;
00073     save_y = y;
00074 
00075     //Do the jump
00076     norme = randomSync.GetDouble(2.0, 5.0);
00077     PutOutOfGround();
00078     SetSpeedXY(Point2d(m_sens * norme , - norme * 3.0));
00079   }
00080 
00081   //Due to a bug in the physic engine
00082   //sometimes, angle==infinite (according to gdb) ??
00083   GetSpeed(norme, angle);
00084 
00085   while(angle < -M_PI)
00086     angle += M_PI;
00087   while(angle > M_PI)
00088     angle -= M_PI;
00089 
00090   angle /= 2.0;
00091   if(m_sens == -1)
00092   {
00093     if(angle > 0)
00094       angle -= M_PI_2;
00095     else
00096       angle += M_PI_2;
00097   }
00098 
00099   if(angle > 4 * M_PI)
00100     angle = 0;
00101 
00102   image->SetRotation_rad(angle);
00103   image->Scale((double)m_sens,1.0);
00104   image->Update();
00105   // Fixe le rectangle de test  ??
00106   SetTestRect ( image->GetWidth()/2-1,
00107                 image->GetWidth()/2-1,
00108                 image->GetHeight()/2-1,
00109                 image->GetHeight()/2-1);
00110 }
00111 
00112 void Gnu::SignalOutOfMap()
00113 {
00114   GameMessages::GetInstance()->Add (_("The Gnu left the battlefield before exploding"));
00115   WeaponProjectile::SignalOutOfMap();
00116 }
00117 //-----------------------------------------------------------------------------
00118 
00119 GnuLauncher::GnuLauncher() :
00120   WeaponLauncher(WEAPON_GNU, "gnulauncher", new ExplosiveWeaponConfig(), VISIBLE_ONLY_WHEN_INACTIVE)
00121 {
00122   m_name = _("Gnu Launcher");
00123   ReloadLauncher();
00124 }
00125 
00126 WeaponProjectile * GnuLauncher::GetProjectileInstance()
00127 {
00128   return dynamic_cast<WeaponProjectile *>
00129       (new Gnu(cfg(),dynamic_cast<WeaponLauncher *>(this)));
00130 }

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