src/weapon/shotgun.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  * Shotgun. Shoot a bunch of buckshot at each fire
00020  *****************************************************************************/
00021 
00022 #include <sstream>
00023 #include "../map/map.h"
00024 #include "../game/time.h"
00025 #include "../object/objects_list.h"
00026 #include "../team/teams_list.h"
00027 #include "../tool/i18n.h"
00028 #include "../interface/game_msg.h"
00029 #include "../network/randomsync.h"
00030 #include "explosion.h"
00031 #include "shotgun.h"
00032 
00033 const uint   SHOTGUN_BUCKSHOT_SPEED  = 30;
00034 const uint   SHOTGUN_EXPLOSION_RANGE = 1;
00035 const double SHOTGUN_RANDOM_ANGLE    = 0.02;
00036 const double SHOTGUN_RANDOM_STRENGTH = 2.0;
00037 const int nb_bullets = 4;
00038 
00039 ShotgunBuckshot::ShotgunBuckshot(ExplosiveWeaponConfig& cfg,
00040                                  WeaponLauncher * p_launcher) :
00041   WeaponBullet("buckshot", cfg, p_launcher)
00042 {
00043   cfg.explosion_range = SHOTGUN_EXPLOSION_RANGE;
00044 }
00045 
00046 void ShotgunBuckshot::RandomizeShoot(double &angle,double &strength)
00047 {
00048   angle += M_PI * randomSync.GetDouble(-SHOTGUN_RANDOM_ANGLE,SHOTGUN_RANDOM_ANGLE);
00049   strength += randomSync.GetDouble(-SHOTGUN_RANDOM_STRENGTH,SHOTGUN_RANDOM_STRENGTH);
00050 }
00051 
00052 bool ShotgunBuckshot::IsOverlapping(const PhysicalObj* obj) const
00053 {
00054   if(GetName() == obj->GetName()) return true;
00055   return m_overlapping_object == obj;
00056 }
00057 
00058 //-----------------------------------------------------------------------------
00059 
00060 Shotgun::Shotgun() : WeaponLauncher(WEAPON_SHOTGUN, "shotgun", new ExplosiveWeaponConfig())
00061 {
00062   m_name = _("Shotgun");
00063 
00064   override_keys = true ;
00065   announce_missed_shots = false;
00066   m_weapon_fire = new Sprite(resource_manager.LoadImage(weapons_res_profile,m_id+"_fire"));
00067   m_weapon_fire->EnableRotationCache(32);
00068 
00069   ReloadLauncher();
00070 }
00071 
00072 // Return a buckshot instance for the shotgun
00073 WeaponProjectile * Shotgun::GetProjectileInstance()
00074 {
00075   return dynamic_cast<WeaponProjectile *>
00076       (new ShotgunBuckshot(cfg(),dynamic_cast<WeaponLauncher *>(this)));
00077 }
00078 
00079 void Shotgun::ShootSound()
00080 {
00081   jukebox.Play("share", "weapon/shotgun");
00082 }
00083 
00084 void Shotgun::IncMissedShots()
00085 {
00086   if(missed_shots + 1 == nb_bullets)
00087     announce_missed_shots = true;
00088   WeaponLauncher::IncMissedShots();
00089 }
00090 
00091 bool Shotgun::p_Shoot ()
00092 {  
00093   missed_shots = 0;
00094   announce_missed_shots = false;
00095   if (m_is_active)
00096     return false;
00097   for(int i = 0; i < nb_bullets; i++) {
00098     projectile->Shoot(SHOTGUN_BUCKSHOT_SPEED);
00099     projectile = NULL;
00100     ReloadLauncher();
00101   }
00102   ShootSound();
00103   m_last_fire_time = Time::GetInstance()->Read();
00104   m_is_active = true;
00105   return true;
00106 }
00107 

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