src/weapon/polecat.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  * Polecat : send a polecat to the enemy. Close character get sick with the mefitic odor.
00020  *****************************************************************************/
00021 
00022 #include "polecat.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 const uint TIME_BETWEEN_FART = 500;
00038 
00039 PolecatFart::PolecatFart(ExplosiveWeaponConfig& cfg,
00040                  WeaponLauncher * p_launcher) :
00041   WeaponProjectile("polecat_fart", cfg, p_launcher)
00042 {
00043   explode_with_collision = false;
00044 }
00045 
00046 Polecat::Polecat(ExplosiveWeaponConfig& cfg,
00047                  WeaponLauncher * p_launcher) :
00048   WeaponProjectile("polecat", cfg, p_launcher)
00049 {
00050   explode_with_collision = false;
00051   last_fart_time = 0;
00052 }
00053 
00054 void Polecat::Shoot (double strength)
00055 {
00056   WeaponProjectile::Shoot(strength);
00057   last_fart_time = Time::GetInstance()->Read() + TIME_BETWEEN_FART;
00058 
00059   save_x=GetX();
00060   save_y=GetY();
00061 
00062   double angle = ActiveCharacter().GetFiringAngle();
00063 
00064   if(angle<M_PI/2 && angle>-M_PI/2)
00065     m_sens = 1;
00066   else
00067     m_sens = -1;
00068 }
00069 
00070 void Polecat::Refresh()
00071 {
00072   WeaponProjectile::Refresh();
00073 
00074   double norme, angle;
00075   //When we hit the ground, jump !
00076   if(!IsMoving() && !FootsInVacuum())
00077   {
00078     //If the GNU is stuck in ground -> change direction
00079     int x = GetX();
00080     int y = GetY();
00081     if(x==save_x && y==save_y)
00082       m_sens = - m_sens;
00083     save_x = x;
00084     save_y = y;
00085 
00086     //Do the jump
00087     norme = randomSync.GetDouble(1.0, 2.0);
00088     PutOutOfGround();
00089     SetSpeedXY(Point2d(m_sens * norme , - norme * 3.0));
00090   }
00091   if (last_fart_time + TIME_BETWEEN_FART < Time::GetInstance()->Read()) {
00092     double norme = randomSync.GetLong(0, 5000)/100;
00093     double angle = randomSync.GetLong(0, 3000)/1000;
00094     ParticleEngine::AddNow(GetPosition(), 1, particle_POLECAT_FART, true, norme, angle);
00095     last_fart_time = Time::GetInstance()->Read();
00096   }
00097   //Due to a bug in the physic engine
00098   //sometimes, angle==infinite (according to gdb) ??
00099   GetSpeed(norme, angle);
00100 
00101   while(angle < -M_PI)
00102     angle += M_PI;
00103   while(angle > M_PI)
00104     angle -= M_PI;
00105 
00106   angle /= 2.0;
00107   if(m_sens == -1)
00108   {
00109     if(angle > 0)
00110       angle -= M_PI_2;
00111     else
00112       angle += M_PI_2;
00113   }
00114 
00115   image->SetRotation_rad(angle);
00116   image->Scale((double)m_sens,1.0);
00117   image->Update();
00118   // Set the test area ?
00119   SetTestRect ( image->GetWidth()/2-1,
00120                 image->GetWidth()/2-1,
00121                 image->GetHeight()/2-1,
00122                 image->GetHeight()/2-1);
00123 }
00124 
00125 void Polecat::SignalOutOfMap()
00126 {
00127   GameMessages::GetInstance()->Add (_("The Polecat left the battlefield before exploding"));
00128   WeaponProjectile::SignalOutOfMap();
00129 }
00130 //-----------------------------------------------------------------------------
00131 
00132 PolecatLauncher::PolecatLauncher() :
00133   WeaponLauncher(WEAPON_POLECAT, "polecatlauncher", new ExplosiveWeaponConfig(), VISIBLE_ONLY_WHEN_INACTIVE)
00134 {
00135   m_name = _("Polecat Launcher");
00136   ReloadLauncher();
00137 }
00138 
00139 WeaponProjectile * PolecatLauncher::GetProjectileInstance()
00140 {
00141   return dynamic_cast<WeaponProjectile *>
00142     (new Polecat(cfg(),dynamic_cast<WeaponLauncher *>(this)));
00143 }

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