1 #pragma once 2 #ifndef CATA_SRC_EXPLOSION_H 3 #define CATA_SRC_EXPLOSION_H 4 5 #include <map> 6 #include <utility> 7 #include <vector> 8 9 #include "optional.h" 10 #include "point.h" 11 #include "type_id.h" 12 13 class JsonObject; 14 class nc_color; 15 16 struct shrapnel_data { 17 int casing_mass = 0; 18 float fragment_mass = 0.005f; 19 // Percentage 20 int recovery = 0; 21 itype_id drop = itype_id::NULL_ID(); 22 23 shrapnel_data() = default; 24 explicit shrapnel_data( int casing_mass, float fragment_mass = 0.005f, int recovery = 0, 25 itype_id drop = itype_id::NULL_ID() ) casing_massshrapnel_data26 : casing_mass( casing_mass ) 27 , fragment_mass( fragment_mass ) 28 , recovery( recovery ) 29 , drop( drop ) { 30 } 31 }; 32 33 struct explosion_data { 34 float power = -1.0f; 35 float distance_factor = 0.8f; 36 int max_noise = 90000000; //Noise generated by an exploding mininuke 37 bool fire = false; 38 shrapnel_data shrapnel; 39 40 /** Returns the distance at which we have `ratio` of initial power. */ 41 float expected_range( float ratio ) const; 42 /** Returns the expected power at a given distance from epicenter. */ 43 float power_at_range( float dist ) const; 44 /** Returns the distance at which the power drops below 1. */ 45 int safe_range() const; 46 47 explosion_data() = default; 48 explicit explosion_data( float power, float distance_factor = 0.8f, bool fire = false, 49 shrapnel_data shrapnel = {} ) powerexplosion_data50 : power( power ) 51 , distance_factor( distance_factor ) 52 , fire( fire ) 53 , shrapnel( shrapnel ) { 54 } 55 }; 56 57 // handles explosion related functions 58 namespace explosion_handler 59 { 60 using queued_explosion = std::pair<tripoint, explosion_data>; 61 static std::vector<queued_explosion> _explosions; 62 63 /** Queue an explosion at p of intensity (power) with (shrapnel) chunks of shrapnel. 64 Explosion intensity formula is roughly power*factor^distance. 65 If factor <= 0, no blast is produced 66 The explosion won't actually occur until process_explosions() */ 67 void explosion( 68 const tripoint &p, float power, float factor = 0.8f, 69 bool fire = false, int casing_mass = 0, float frag_mass = 0.05 70 ); 71 72 void explosion( const tripoint &p, const explosion_data &ex ); 73 void _make_explosion( const tripoint &p, const explosion_data &ex ); 74 75 /** Triggers a flashbang explosion at p. */ 76 void flashbang( const tripoint &p, bool player_immune = false ); 77 /** Triggers a resonance cascade at p. */ 78 void resonance_cascade( const tripoint &p ); 79 /** Triggers a scrambler blast at p. */ 80 void scrambler_blast( const tripoint &p ); 81 /** Triggers an EMP blast at p. */ 82 void emp_blast( const tripoint &p ); 83 // shockwave applies knockback to all targets within radius of p 84 // parameters force, stun, and dam_mult are passed to knockback() 85 // ignore_player determines if player is affected, useful for bionic, etc. 86 void shockwave( const tripoint &p, int radius, int force, int stun, int dam_mult, 87 bool ignore_player ); 88 89 void draw_explosion( const tripoint &p, int radius, const nc_color &col ); 90 void draw_custom_explosion( const tripoint &p, const std::map<tripoint, nc_color> &area, 91 const cata::optional<std::string> &tile_id = cata::nullopt ); 92 93 void process_explosions(); 94 } // namespace explosion_handler 95 96 shrapnel_data load_shrapnel_data( const JsonObject &jo ); 97 explosion_data load_explosion_data( const JsonObject &jo ); 98 99 #endif // CATA_SRC_EXPLOSION_H 100