Skip to content

Commit 776c297

Browse files
authored
Merge pull request #75168 from GuardianDll/always_cast_spell_ammo
add `always_cast_spell` ammo effect boolean
2 parents 093c3f1 + 39062d4 commit 776c297

File tree

8 files changed

+16
-6
lines changed

8 files changed

+16
-6
lines changed

data/mods/Aftershock/ammo_effects.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,13 @@
4949
{
5050
"id": "ELECTRIC_CHAIN",
5151
"type": "ammo_effect",
52+
"always_cast_spell": true,
5253
"spell_data": { "id": "spell_electric_chain" }
5354
},
5455
{
5556
"id": "FUSION_FAN",
5657
"type": "ammo_effect",
58+
"always_cast_spell": true,
5759
"spell_data": { "id": "spell_fusion_fan" }
5860
},
5961
{

doc/JSON_INFO.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3588,6 +3588,9 @@ ammo_effects define what effect the projectile, that you shoot, would have. List
35883588
"do_flashbang": false, // Creates a one tile radius EMP explosion at the hit location; default false
35893589
"do_emp_blast": false // Creates a hardcoded flashbang explosion; default false
35903590
"foamcrete_build": false // Creates foamcrete fields and walls on the hit location, used in aftershock; default false
3591+
"spell_data": { "id": "bear_trap" } // Spell, that would be casted when projectile hits an enemy
3592+
"spell_data": { "id": "release_the_deltas", "hit_self": true, "min_level": 10 }, //another example
3593+
"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.
35913594
}
35923595
```
35933596

src/ammo_effect.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ void ammo_effect::load( const JsonObject &jo, const std::string_view )
9494
optional( jo, was_loaded, "do_emp_blast", do_emp_blast, false );
9595
optional( jo, was_loaded, "foamcrete_build", foamcrete_build, false );
9696
optional( jo, was_loaded, "spell_data", spell_data );
97+
optional( jo, was_loaded, "always_cast_spell", always_cast_spell, false );
9798

9899

99100
}

src/ammo_effect.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ struct ammo_effect {
4545
bool do_flashbang = false;
4646
bool do_emp_blast = false;
4747
bool foamcrete_build = false;
48+
bool always_cast_spell = false;
4849

4950
field_type_id trail_field_type = fd_null.id_or( INVALID_FIELD_TYPE_ID );
5051
/** used during JSON loading only */

src/ballistics.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,8 @@ dealt_projectile_attack projectile_attack( const projectile &proj_arg, const tri
521521

522522
drop_or_embed_projectile( attack );
523523

524-
apply_ammo_effects( null_source ? nullptr : origin, tp, proj.proj_effects );
524+
bool dealt_damage = attack.dealt_dam.total_damage() > 0;
525+
apply_ammo_effects( null_source ? nullptr : origin, tp, proj.proj_effects, dealt_damage );
525526
const explosion_data &expl = proj.get_custom_explosion();
526527
if( expl.power > 0.0f ) {
527528
explosion_handler::explosion( null_source ? nullptr : origin, tp, proj.get_custom_explosion() );

src/item.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12561,7 +12561,7 @@ bool item::detonate( const tripoint &p, std::vector<item> &drops )
1256112561
const int rounds_exploded = rng( 1, charges_remaining / 2 );
1256212562
if( type->ammo->special_cookoff ) {
1256312563
// If it has a special effect just trigger it.
12564-
apply_ammo_effects( nullptr, p, type->ammo->ammo_effects );
12564+
apply_ammo_effects( nullptr, p, type->ammo->ammo_effects, true );
1256512565
}
1256612566
if( type->ammo->cookoff ) {
1256712567
// If ammo type can burn, then create an explosion proportional to quantity.

src/projectile.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ static void foamcrete_build( const tripoint &p )
142142
}
143143

144144
void apply_ammo_effects( const Creature *source, const tripoint &p,
145-
const std::set<ammo_effect_str_id> &effects )
145+
const std::set<ammo_effect_str_id> &effects, const bool dealt_damage )
146146
{
147147
map &here = get_map();
148148
Character &player_character = get_player_character();
@@ -189,8 +189,10 @@ void apply_ammo_effects( const Creature *source, const tripoint &p,
189189
//cast ammo effect spells
190190
const spell ammo_spell = ae.spell_data.get_spell();
191191
if( ammo_spell.is_valid() ) {
192-
ammo_spell.cast_all_effects( *const_cast<Creature *>( source ), p );
193-
ammo_spell.make_sound( p, *const_cast<Creature *>( source ) );
192+
if( ae.always_cast_spell || dealt_damage ) {
193+
ammo_spell.cast_all_effects( *const_cast<Creature *>( source ), p );
194+
ammo_spell.make_sound( p, *const_cast<Creature *>( source ) );
195+
}
194196
}
195197
}
196198
}

src/projectile.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ struct dealt_projectile_attack {
7575
};
7676

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

8181
void multi_projectile_hit_message( Creature *critter, int hit_count, int damage_taken,

0 commit comments

Comments
 (0)