src/weapon/explosion.h File Reference

#include <SDL.h>
#include "weapon.h"
#include "../graphic/surface.h"
#include "../include/base.h"
#include "../object/physical_obj.h"
#include "../particles/particle.h"
#include "../tool/point.h"
#include "../tool/resource_manager.h"

Include dependency graph for explosion.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void ApplyExplosion (const Point2i &pos, const ExplosiveWeaponConfig &config, const std::string &son="weapon/explosion", bool fire_particle=true, ParticleEngine::ESmokeStyle smoke=ParticleEngine::BigESmoke)
void ApplyExplosion_common (const Point2i &pos, const ExplosiveWeaponConfig &config, const std::string &son, bool fire_particle, ParticleEngine::ESmokeStyle smoke)

Variables

Profileweapons_res_profile


Function Documentation

void ApplyExplosion ( const Point2i pos,
const ExplosiveWeaponConfig config,
const std::string &  son = "weapon/explosion",
bool  fire_particle = true,
ParticleEngine::ESmokeStyle  smoke = ParticleEngine::BigESmoke 
)

Definition at line 46 of file explosion.cpp.

00052 {
00053   if(network.IsLocal())
00054     ApplyExplosion_common(pos, config, son, fire_particle, smoke);
00055   else
00056   if(network.IsServer())
00057     ApplyExplosion_server(pos, config, son, fire_particle, smoke);
00058   else
00059   if(network.IsClient())
00060     return;
00061   // client receives explosion via the action handler
00062 }

Here is the call graph for this function:

Here is the caller graph for this function:

void ApplyExplosion_common ( const Point2i pos,
const ExplosiveWeaponConfig config,
const std::string &  son,
bool  fire_particle,
ParticleEngine::ESmokeStyle  smoke 
)

Definition at line 64 of file explosion.cpp.

00070 {
00071   MSG_DEBUG("explosion", "explosion range : %i\n", config.explosion_range);
00072 
00073 #ifdef HAVE_A_REALLY_BIG_CPU
00074   // Add particles based on the ground image
00075   if(config.explosion_range >= 15)
00076   {
00077     for(int y=-config.explosion_range; y < (int)config.explosion_range; y += 10)
00078     {
00079       int dx = (int) (cos(asin((float)y / config.explosion_range)) * (float) y);
00080       for(int x=-dx; x < dx; x += 10)
00081         ParticleEngine::AddNow(pos + Point2i(x-5,y-5), 1, particle_GROUND, true);
00082     }
00083   }
00084   else
00085     ParticleEngine::AddNow(pos, 1, particle_GROUND, true);
00086 #endif
00087 
00088   // Make a hole in the ground
00089   world.Dig(pos, config.explosion_range);
00090 
00091   // Play a sound
00092   jukebox.Play("share", son);
00093 
00094   // Apply damage on the character.
00095   // Do not care about the death of the active worm.
00096   double highest_force = 0.0;
00097   Character* fastest_character = NULL;
00098   FOR_ALL_CHARACTERS(equipe,ver)
00099   {
00100     double distance = pos.Distance(ver -> GetCenter());
00101     if(distance < 1.0)
00102       distance = 1.0;
00103 
00104     // If the character is in the explosion range, apply damage on it !
00105     if (distance <= config.explosion_range)
00106     {
00107       MSG_DEBUG("explosion", "\n*Character %s : distance= %f", ver->GetName().c_str(), distance);
00108       double dmg = cos(M_PI_2 * distance / config.explosion_range);
00109       dmg *= config.damage;
00110       MSG_DEBUG("explosion", "hit_point_loss energy= %i", ver->GetName().c_str(), dmg);
00111       ver -> SetEnergyDelta (-(int)dmg);
00112     }
00113 
00114     // If the character is in the blast range, apply the blast on it !
00115     if (distance <= config.blast_range)
00116     {
00117       double angle;
00118       double force = cos(M_PI_2 * distance / config.blast_range);
00119       force *= config.blast_force;
00120 
00121       if ( force > highest_force )
00122       {
00123         fastest_character = &(*ver);
00124         highest_force = force;
00125       }
00126 
00127       if (!EgalZero(distance))
00128       {
00129         angle  = pos.ComputeAngle(ver -> GetCenter());
00130         if( angle > 0 )
00131           angle  = - angle;
00132       }
00133       else
00134         angle = -M_PI/2;
00135 
00136 
00137       MSG_DEBUG("explosion", "force = %f", force);
00138       ver->AddSpeed (force / ver->GetMass(), angle);
00139       ver->SignalExplosion();
00140     }
00141   }
00142 
00143   if(fastest_character != NULL)
00144     camera.FollowObject (fastest_character, true, true);
00145 
00146   // Apply the blast on physical objects.
00147   FOR_EACH_OBJECT(it)
00148    {
00149      PhysicalObj *obj = *it;
00150      if (!obj->GoesThroughWall() && !obj->IsGhost())
00151      {
00152        double distance = pos.Distance(obj->GetCenter());
00153        if(distance < 1.0)
00154          distance = 1.0;
00155 
00156        if (distance <= config.explosion_range)
00157        {
00158          double dmg = cos(M_PI_2 * distance / config.explosion_range);
00159          dmg *= config.damage;
00160          obj->AddDamage (config.damage);
00161        }
00162 
00163        if (distance <= config.blast_range)
00164        {
00165          double angle;
00166          double force = cos(M_PI_2 * distance / config.blast_range);
00167          force *= config.blast_force;
00168 
00169          if (!EgalZero(distance))
00170            angle  = pos.ComputeAngle(obj->GetCenter());
00171          else
00172            angle = -M_PI_2;
00173 
00174          if(fastest_character != NULL)
00175            camera.FollowObject (obj, true, true);
00176          obj->AddSpeed (force / obj->GetMass(), angle);
00177        }
00178      }
00179    }
00180 
00181   ParticleEngine::AddExplosionSmoke(pos, config.particle_range, smoke);
00182 
00183   // Do we need to generate some fire particles ?
00184   if (fire_particle)
00185      ParticleEngine::AddNow(pos , 5, particle_FIRE, true);
00186 }

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Profile* weapons_res_profile

Definition at line 37 of file explosion.cpp.


Generated on Mon Jan 1 13:29:07 2007 for Wormux by  doxygen 1.4.7