Skip to content

Commit

Permalink
Merge pull request #75168 from GuardianDll/always_cast_spell_ammo
Browse files Browse the repository at this point in the history
add `always_cast_spell` ammo effect boolean
  • Loading branch information
Maleclypse authored Jul 23, 2024
2 parents 093c3f1 + 39062d4 commit 776c297
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 6 deletions.
2 changes: 2 additions & 0 deletions data/mods/Aftershock/ammo_effects.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@
{
"id": "ELECTRIC_CHAIN",
"type": "ammo_effect",
"always_cast_spell": true,
"spell_data": { "id": "spell_electric_chain" }
},
{
"id": "FUSION_FAN",
"type": "ammo_effect",
"always_cast_spell": true,
"spell_data": { "id": "spell_fusion_fan" }
},
{
Expand Down
3 changes: 3 additions & 0 deletions doc/JSON_INFO.md
Original file line number Diff line number Diff line change
Expand Up @@ -3588,6 +3588,9 @@ ammo_effects define what effect the projectile, that you shoot, would have. List
"do_flashbang": false, // Creates a one tile radius EMP explosion at the hit location; default false
"do_emp_blast": false // Creates a hardcoded flashbang explosion; default false
"foamcrete_build": false // Creates foamcrete fields and walls on the hit location, used in aftershock; default false
"spell_data": { "id": "bear_trap" } // Spell, that would be casted when projectile hits an enemy
"spell_data": { "id": "release_the_deltas", "hit_self": true, "min_level": 10 }, //another example
"always_cast_spell ": false // if spell_data is used, and this is true, spell would be casted even if projectile did not deal any damage. Default false.
}
```

Expand Down
1 change: 1 addition & 0 deletions src/ammo_effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ void ammo_effect::load( const JsonObject &jo, const std::string_view )
optional( jo, was_loaded, "do_emp_blast", do_emp_blast, false );
optional( jo, was_loaded, "foamcrete_build", foamcrete_build, false );
optional( jo, was_loaded, "spell_data", spell_data );
optional( jo, was_loaded, "always_cast_spell", always_cast_spell, false );


}
Expand Down
1 change: 1 addition & 0 deletions src/ammo_effect.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ struct ammo_effect {
bool do_flashbang = false;
bool do_emp_blast = false;
bool foamcrete_build = false;
bool always_cast_spell = false;

field_type_id trail_field_type = fd_null.id_or( INVALID_FIELD_TYPE_ID );
/** used during JSON loading only */
Expand Down
3 changes: 2 additions & 1 deletion src/ballistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,8 @@ dealt_projectile_attack projectile_attack( const projectile &proj_arg, const tri

drop_or_embed_projectile( attack );

apply_ammo_effects( null_source ? nullptr : origin, tp, proj.proj_effects );
bool dealt_damage = attack.dealt_dam.total_damage() > 0;
apply_ammo_effects( null_source ? nullptr : origin, tp, proj.proj_effects, dealt_damage );
const explosion_data &expl = proj.get_custom_explosion();
if( expl.power > 0.0f ) {
explosion_handler::explosion( null_source ? nullptr : origin, tp, proj.get_custom_explosion() );
Expand Down
2 changes: 1 addition & 1 deletion src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12561,7 +12561,7 @@ bool item::detonate( const tripoint &p, std::vector<item> &drops )
const int rounds_exploded = rng( 1, charges_remaining / 2 );
if( type->ammo->special_cookoff ) {
// If it has a special effect just trigger it.
apply_ammo_effects( nullptr, p, type->ammo->ammo_effects );
apply_ammo_effects( nullptr, p, type->ammo->ammo_effects, true );
}
if( type->ammo->cookoff ) {
// If ammo type can burn, then create an explosion proportional to quantity.
Expand Down
8 changes: 5 additions & 3 deletions src/projectile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ static void foamcrete_build( const tripoint &p )
}

void apply_ammo_effects( const Creature *source, const tripoint &p,
const std::set<ammo_effect_str_id> &effects )
const std::set<ammo_effect_str_id> &effects, const bool dealt_damage )
{
map &here = get_map();
Character &player_character = get_player_character();
Expand Down Expand Up @@ -189,8 +189,10 @@ void apply_ammo_effects( const Creature *source, const tripoint &p,
//cast ammo effect spells
const spell ammo_spell = ae.spell_data.get_spell();
if( ammo_spell.is_valid() ) {
ammo_spell.cast_all_effects( *const_cast<Creature *>( source ), p );
ammo_spell.make_sound( p, *const_cast<Creature *>( source ) );
if( ae.always_cast_spell || dealt_damage ) {
ammo_spell.cast_all_effects( *const_cast<Creature *>( source ), p );
ammo_spell.make_sound( p, *const_cast<Creature *>( source ) );
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/projectile.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ struct dealt_projectile_attack {
};

void apply_ammo_effects( const Creature *source, const tripoint &p,
const std::set<ammo_effect_str_id> &effects );
const std::set<ammo_effect_str_id> &effects, bool dealt_damage );
int max_aoe_size( const std::set<ammo_effect_str_id> &tags );

void multi_projectile_hit_message( Creature *critter, int hit_count, int damage_taken,
Expand Down

0 comments on commit 776c297

Please sign in to comment.