Skip to content

Commit

Permalink
Added trail property for ammo effects (#37193)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhilkinSerg authored Jan 31, 2020
1 parent 2c15909 commit 5b19149
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 31 deletions.
43 changes: 42 additions & 1 deletion data/json/ammo_effects.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@
{
"id": "PLASMA",
"type": "ammo_effect",
"aoe": { "field_type": "fd_plasma", "intensity_min": 2, "intensity_max": 3, "chance": 2 }
"aoe": { "field_type": "fd_plasma", "intensity_min": 2, "intensity_max": 3, "chance": 2 },
"trail": { "field_type": "fd_plasma", "intensity_min": 1, "intensity_max": 2, "chance": 50 }
},
{
"id": "EXPLOSIVE_HUGE",
Expand Down Expand Up @@ -150,5 +151,45 @@
"id": "EMP",
"type": "ammo_effect",
"do_emp_blast": true
},
{
"id": "TRAIL",
"type": "ammo_effect",
"trail": { "field_type": "fd_smoke", "intensity_min": 1, "intensity_max": 2, "chance": 75 }
},
{
"id": "STREAM",
"type": "ammo_effect",
"trail": { "field_type": "fd_fire", "intensity_min": 1, "intensity_max": 2, "chance": 66 }
},
{
"id": "STREAM_BIG",
"type": "ammo_effect",
"trail": { "field_type": "fd_fire", "intensity_min": 2, "intensity_max": 2, "chance": 75 }
},
{
"id": "STREAM_GAS_FUNGICIDAL",
"type": "ammo_effect",
"trail": { "field_type": "fd_fungicidal_gas", "intensity_min": 1, "intensity_max": 2, "chance": 66 }
},
{
"id": "STREAM_GAS_INSCENTICIDAL",
"type": "ammo_effect",
"trail": { "field_type": "fd_insecticidal_gas", "intensity_min": 1, "intensity_max": 2, "chance": 66 }
},
{
"id": "LIGHTNING",
"type": "ammo_effect",
"trail": { "field_type": "fd_electricity", "intensity_min": 2, "intensity_max": 3 }
},
{
"id": "LASER",
"type": "ammo_effect",
"trail": { "field_type": "fd_laser", "intensity_min": 2, "intensity_max": 2 }
},
{
"id": "DRAW_LASER_BEAM",
"type": "ammo_effect",
"trail": { "field_type": "fd_laser", "intensity_min": 2, "intensity_max": 2 }
}
]
21 changes: 21 additions & 0 deletions src/ammo_effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ void ammo_effect::load( const JsonObject &jo, const std::string & )
optional( joa, was_loaded, "check_sees", aoe_check_sees, false );
optional( joa, was_loaded, "check_sees_radius", aoe_check_sees_radius, 0 );
}
if( jo.has_member( "trail" ) ) {
JsonObject joa = jo.get_object( "trail" );
optional( joa, was_loaded, "field_type", trail_field_type_name, "fd_null" );
optional( joa, was_loaded, "intensity_min", trail_intensity_min, 0 );
optional( joa, was_loaded, "intensity_max", trail_intensity_max, 0 );
optional( joa, was_loaded, "chance", trail_chance, 1 );
}
if( jo.has_member( "explosion" ) ) {
JsonObject joe = jo.get_object( "explosion" );
aoe_explosion_data = load_explosion_data( joe );
Expand All @@ -85,6 +92,7 @@ void ammo_effect::finalize()
{
for( const ammo_effect &ae : ammo_effects::get_all() ) {
const_cast<ammo_effect &>( ae ).aoe_field_type = field_type_id( ae.aoe_field_type_name );
const_cast<ammo_effect &>( ae ).trail_field_type = field_type_id( ae.trail_field_type_name );
}

}
Expand Down Expand Up @@ -112,6 +120,19 @@ void ammo_effect::check() const
if( aoe_intensity_max < aoe_intensity_min ) {
debugmsg( "Maximum intensity must be greater than or equal to minimum intensity" );
}
if( !trail_field_type.is_valid() ) {
debugmsg( "No such field type %s", trail_field_type_name );
}
if( trail_chance > 100 || trail_chance <= 0 ) {
debugmsg( "Field chance divisor cannot be negative" );
debugmsg( "Field chance of %s out of range (%d of min 1 max 100)", id.c_str(), trail_chance );
}
if( trail_intensity_min < 0 ) {
debugmsg( "Field intensity cannot be negative" );
}
if( trail_intensity_max < trail_intensity_min ) {
debugmsg( "Maximum intensity must be greater than or equal to minimum intensity" );
}
}

size_t ammo_effect::count()
Expand Down
7 changes: 7 additions & 0 deletions src/ammo_effect.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ struct ammo_effect {
bool do_flashbang = false;
bool do_emp_blast = false;

field_type_id trail_field_type = fd_null;
/** used during JSON loading only */
std::string trail_field_type_name = "fd_null";
int trail_intensity_min = 0;
int trail_intensity_max = 0;
int trail_chance = 100;

public:
// Used by generic_factory
string_id<ammo_effect> id;
Expand Down
37 changes: 7 additions & 30 deletions src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <unordered_map>

#include "ammo.h"
#include "ammo_effect.h"
#include "artifact.h"
#include "avatar.h"
#include "calendar.h"
Expand Down Expand Up @@ -3550,36 +3551,12 @@ void map::shoot( const tripoint &p, projectile &proj, const bool hit_items )
dam = 0;
}

if( ammo_effects.count( "TRAIL" ) && !one_in( 4 ) ) {
add_field( p, fd_smoke, rng( 1, 2 ) );
}

if( ammo_effects.count( "STREAM" ) && !one_in( 3 ) ) {
add_field( p, fd_fire, rng( 1, 2 ) );
}

if( ammo_effects.count( "STREAM_GAS_FUNGICIDAL" ) && !one_in( 3 ) ) {
add_field( p, fd_fungicidal_gas, rng( 1, 2 ) );
}

if( ammo_effects.count( "STREAM_GAS_INSCENTICIDAL" ) && !one_in( 3 ) ) {
add_field( p, fd_insecticidal_gas, rng( 1, 2 ) );
}

if( ammo_effects.count( "STREAM_BIG" ) && !one_in( 4 ) ) {
add_field( p, fd_fire, 2 );
}

if( ammo_effects.count( "LIGHTNING" ) ) {
add_field( p, fd_electricity, rng( 2, 3 ) );
}

if( ammo_effects.count( "PLASMA" ) && one_in( 2 ) ) {
add_field( p, fd_plasma, rng( 1, 2 ) );
}

if( ammo_effects.count( "LASER" ) || ammo_effects.count( "DRAW_LASER_BEAM" ) ) {
add_field( p, fd_laser, 2 );
for( const ammo_effect &ae : ammo_effects::get_all() ) {
if( ammo_effects.count( ae.id.str() ) > 0 ) {
if( x_in_y( ae.trail_chance, 100 ) ) {
g->m.add_field( p, ae.trail_field_type, rng( ae.trail_intensity_min, ae.trail_intensity_max ) );
}
}
}

dam = std::max( 0.0f, dam );
Expand Down

0 comments on commit 5b19149

Please sign in to comment.