src/weapon/cluster_bomb.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  * Cluster Bomb : launch a grenade will exploding, it produce new little cluster
00020  * exploding bomb
00021  *****************************************************************************/
00022 
00023 #include "cluster_bomb.h"
00024 #include <sstream>
00025 #include <math.h>
00026 #include "explosion.h"
00027 #include "../game/time.h"
00028 #include "../graphic/video.h"
00029 #include "../interface/game_msg.h"
00030 #include "../map/camera.h"
00031 #include "../object/objects_list.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 Cluster::Cluster(ClusterBombConfig& cfg,
00038                  WeaponLauncher * p_launcher) :
00039   WeaponProjectile ("cluster", cfg, p_launcher)
00040 {
00041   explode_colliding_character = true;
00042 }
00043 
00044 void Cluster::Shoot (int x, int y)
00045 {
00046   camera.FollowObject(this, true, false);
00047   ResetConstants();
00048   SetXY( Point2i(x, y) );
00049 }
00050 
00051 void Cluster::Refresh()
00052 {
00053   image->SetRotation_rad(GetSpeedAngle());
00054 }
00055 
00056 void Cluster::SignalOutOfMap()
00057 {
00058   GameMessages::GetInstance()->Add (_("The rocket has left the battlefield..."));
00059   WeaponProjectile::SignalOutOfMap();
00060 }
00061 
00062 void Cluster::DoExplosion()
00063 {
00064   ApplyExplosion (GetPosition(), cfg, "weapon/explosion", false, ParticleEngine::LittleESmoke);
00065 }
00066 
00067 //-----------------------------------------------------------------------------
00068 
00069 ClusterBomb::ClusterBomb(ClusterBombConfig& cfg,
00070                          WeaponLauncher * p_launcher)
00071   : WeaponProjectile ("cluster_bomb", cfg, p_launcher)
00072 {
00073   m_rebound_sound = "weapon/grenade_bounce";
00074   explode_with_collision = false;
00075 }
00076 
00077 void ClusterBomb::Refresh()
00078 {
00079   WeaponProjectile::Refresh();
00080   image->SetRotation_rad(GetSpeedAngle());
00081 }
00082 
00083 void ClusterBomb::SignalOutOfMap()
00084 {
00085   GameMessages::GetInstance()->Add (_("The Cluster Bomb has left the battlefield before it could explode."));
00086   WeaponProjectile::SignalOutOfMap();
00087 }
00088 
00089 void ClusterBomb::DoExplosion()
00090 {
00091   const uint nb = static_cast<ClusterBombConfig &>(cfg).nb_fragments;
00092   Cluster * cluster;
00093   for (uint i=0; i<nb; ++i) {
00094     double angle = randomSync.GetDouble(2.0 * M_PI);
00095     int x = GetX()+(int)(cos(angle) * (double)cfg.blast_range * 0.9);
00096     int y = GetY()+(int)(sin(angle) * (double)cfg.blast_range * 0.9);
00097     cluster = new Cluster(static_cast<ClusterBombConfig &>(cfg), launcher);
00098     cluster->Shoot(x,y);
00099     lst_objects.AddObject(cluster);
00100   }
00101   WeaponProjectile::DoExplosion();
00102 }
00103 
00104 //-----------------------------------------------------------------------------
00105 
00106 ClusterLauncher::ClusterLauncher() :
00107   WeaponLauncher(WEAPON_CLUSTER_BOMB, "cluster_bomb", new ClusterBombConfig(), VISIBLE_ONLY_WHEN_INACTIVE)
00108 {
00109   m_name = _("Cluster Bomb");
00110   ignore_collision_signal = true;
00111   ReloadLauncher();
00112 }
00113 
00114 WeaponProjectile * ClusterLauncher::GetProjectileInstance()
00115 {
00116   return dynamic_cast<WeaponProjectile *>
00117       (new ClusterBomb(cfg(),dynamic_cast<WeaponLauncher *>(this)));
00118 }
00119 
00120 ClusterBombConfig& ClusterLauncher::cfg()
00121 {
00122   return static_cast<ClusterBombConfig&>(*extra_params);
00123 }
00124 
00125 //-----------------------------------------------------------------------------
00126 
00127 ClusterBombConfig::ClusterBombConfig() :
00128   ExplosiveWeaponConfig()
00129 {
00130   nb_fragments = 5;
00131 }
00132 
00133 void ClusterBombConfig::LoadXml(xmlpp::Element *elem)
00134 {
00135   ExplosiveWeaponConfig::LoadXml(elem);
00136   XmlReader::ReadUint(elem, "nb_fragments", nb_fragments);
00137 }

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