Skip to content

Commit 4c6c25e

Browse files
authored
Merge pull request #82260 from sparr/dedupe_eoc_activation_only
2 parents 8330b3c + f80240f commit 4c6c25e

14 files changed

+44
-92
lines changed

src/bionics.cpp

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -784,11 +784,7 @@ bool Character::activate_bionic( bionic &bio, bool eff_only, bool *close_bionics
784784
dialogue d( get_talker_for( *this ), nullptr );
785785
write_var_value( var_type::context, "act_cost", &d,
786786
units::to_millijoule( bio.info().power_activate ) );
787-
if( eoc->type == eoc_type::ACTIVATION ) {
788-
eoc->activate( d );
789-
} else {
790-
debugmsg( "Must use an activation eoc for a bionic activation. If you don't want the effect_on_condition to happen on its own (without the bionic being activated), remove the recurrence min and max. Otherwise, create a non-recurring effect_on_condition for this bionic with its condition and effects, then have a recurring one queue it." );
791-
}
787+
eoc->activate_activation_only( d, "a bionic activation", "bionic being activated", "bionic" );
792788
}
793789

794790
item tmp_item;
@@ -1239,11 +1235,7 @@ bool Character::deactivate_bionic( bionic &bio, bool eff_only )
12391235

12401236
for( const effect_on_condition_id &eoc : bio.id->deactivated_eocs ) {
12411237
dialogue d( get_talker_for( *this ), nullptr );
1242-
if( eoc->type == eoc_type::ACTIVATION ) {
1243-
eoc->activate( d );
1244-
} else {
1245-
debugmsg( "Must use an activation eoc for a bionic deactivation. If you don't want the effect_on_condition to happen on its own (without the bionic being activated), remove the recurrence min and max. Otherwise, create a non-recurring effect_on_condition for this bionic with its condition and effects, then have a recurring one queue it." );
1246-
}
1238+
eoc->activate_activation_only( d, "a bionic deactivation", "bionic being activated", "bionic" );
12471239
}
12481240

12491241
if( bio.info().has_flag( json_flag_BIONIC_WEAPON ) ) {
@@ -1623,11 +1615,7 @@ void Character::process_bionic( bionic &bio )
16231615

16241616
for( const effect_on_condition_id &eoc : bio.id->processed_eocs ) {
16251617
dialogue d( get_talker_for( *this ), nullptr );
1626-
if( eoc->type == eoc_type::ACTIVATION ) {
1627-
eoc->activate( d );
1628-
} else {
1629-
debugmsg( "Must use an activation eoc for a bionic process. If you don't want the effect_on_condition to happen on its own (without the bionic being activated), remove the recurrence min and max. Otherwise, create a non-recurring effect_on_condition for this bionic with its condition and effects, then have a recurring one queue it." );
1630-
}
1618+
eoc->activate_activation_only( d, "a bionic process", "bionic being activated", "bionic" );
16311619
}
16321620

16331621
// Bionic effects on every turn they are active go here.

src/crafting.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1587,12 +1587,8 @@ void Character::complete_craft( item &craft, const std::optional<tripoint_bub_ms
15871587
inv->restack( *this );
15881588
for( const effect_on_condition_id &eoc : making.result_eocs ) {
15891589
dialogue d( get_talker_for( *this ), nullptr );
1590-
if( eoc->type == eoc_type::ACTIVATION ) {
1591-
for( int i = 0; i < batch_size; i++ ) {
1592-
eoc->activate( d );
1593-
}
1594-
} else {
1595-
debugmsg( "Must use an activation eoc for a recipe. If you don't want the effect_on_condition to happen on its own, remove the recurrence min and max. Otherwise, create a non-recurring effect_on_condition for this recipe with its condition and effects, then have a recurring one queue it." );
1590+
for( int i = 0; i < batch_size; i++ ) {
1591+
eoc->activate_activation_only( d, "a recipe", "crafting", "recipe" );
15961592
}
15971593
}
15981594
}

src/damage.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -394,11 +394,8 @@ void damage_type::onhit_effects( Creature *source, Creature *target ) const
394394
dialogue d( source == nullptr ? nullptr : get_talker_for( source ),
395395
target == nullptr ? nullptr : get_talker_for( target ) );
396396

397-
if( eoc->type == eoc_type::ACTIVATION ) {
398-
eoc->activate( d );
399-
} else {
400-
debugmsg( "Must use an activation eoc for a damage type effect. If you don't want the effect_on_condition to happen on its own (without the damage type effect being activated), remove the recurrence min and max. Otherwise, create a non-recurring effect_on_condition for this damage type with its condition and effects, then have a recurring one queue it." );
401-
}
397+
eoc->activate_activation_only( d, "a damage type effect", "damage type effect being activated",
398+
"damage type" );
402399
}
403400
}
404401

@@ -439,11 +436,8 @@ void damage_type::ondamage_effects( Creature *source, Creature *target, bodypart
439436
d.set_value( "total_damage", total_damage );
440437
d.set_value( "bp", bp.str() );
441438

442-
if( eoc->type == eoc_type::ACTIVATION ) {
443-
eoc->activate( d );
444-
} else {
445-
debugmsg( "Must use an activation eoc for a damage type effect. If you don't want the effect_on_condition to happen on its own (without the damage type effect being activated), remove the recurrence min and max. Otherwise, create a non-recurring effect_on_condition for this damage type with its condition and effects, then have a recurring one queue it." );
446-
}
439+
eoc->activate_activation_only( d, "a damage type effect", "damage type effect being activated",
440+
"damage type" );
447441
}
448442
}
449443

src/effect_on_condition.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,24 @@ bool effect_on_condition::activate( dialogue &d, bool require_callstack_check )
360360
return retval;
361361
}
362362

363+
bool effect_on_condition::activate_activation_only( dialogue &d, const std::string &text1,
364+
const std::string &text2, const std::string &text3, bool require_callstack_check ) const
365+
{
366+
if( type == eoc_type::ACTIVATION ) {
367+
return activate( d, require_callstack_check );
368+
}
369+
debugmsg(
370+
"Must use an activation eoc for %s%s%s%s. Otherwise, create a non-recurring effect_on_condition for this %s%swith its condition and effects, then have a recurring one queue it.",
371+
text1,
372+
text2.empty() ? "" :
373+
". If you don't want the effect_on_condition to happen on its own (without the ",
374+
text2,
375+
text2.empty() ? "" : "), remove the recurrence min and max.",
376+
text3,
377+
text3.empty() ? "" : " " );
378+
return false;
379+
}
380+
363381
bool effect_on_condition::check_deactivate( const_dialogue const &d ) const
364382
{
365383
if( !has_deactivate_condition || has_false_effect ) {

src/effect_on_condition.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ struct effect_on_condition {
6767
event_type required_event;
6868
duration_or_var recurrence;
6969
bool activate( dialogue &d, bool require_callstack_check = true ) const;
70+
bool activate_activation_only( dialogue &d, const std::string &text1, const std::string &text2 = "",
71+
const std::string &text3 = "", bool require_callstack_check = true ) const;
7072
bool check_deactivate( const_dialogue const &d ) const;
7173
bool test_condition( const_dialogue const &d ) const;
7274
void apply_true_effects( dialogue &d ) const;

src/game.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14442,21 +14442,13 @@ void avatar_moves( const tripoint_abs_ms &old_abs_pos, const avatar &u, const ma
1444214442
if( !past_ter->get_exit_EOC().is_null() ) {
1444314443
dialogue d( get_talker_for( get_avatar() ), nullptr );
1444414444
effect_on_condition_id eoc = cur_ter->get_exit_EOC();
14445-
if( eoc->type == eoc_type::ACTIVATION ) {
14446-
eoc->activate( d );
14447-
} else {
14448-
debugmsg( "Must use an activation eoc for OMT movement. Otherwise, create a non-recurring effect_on_condition for this with its condition and effects, then have a recurring one queue it." );
14449-
}
14445+
eoc->activate_activation_only( d, "OMT movement" );
1445014446
}
1445114447

1445214448
if( !cur_ter->get_entry_EOC().is_null() ) {
1445314449
dialogue d( get_talker_for( get_avatar() ), nullptr );
1445414450
effect_on_condition_id eoc = cur_ter->get_entry_EOC();
14455-
if( eoc->type == eoc_type::ACTIVATION ) {
14456-
eoc->activate( d );
14457-
} else {
14458-
debugmsg( "Must use an activation eoc for OMT movement. Otherwise, create a non-recurring effect_on_condition for this with its condition and effects, then have a recurring one queue it." );
14459-
}
14451+
eoc->activate_activation_only( d, "OMT movement" );
1446014452
}
1446114453

1446214454
}

src/iuse_actor.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6155,11 +6155,7 @@ std::optional<int> effect_on_conditions_actor::use( Character *p, item &it,
61556155
dialogue d( ( char_ptr == nullptr ? nullptr : get_talker_for( char_ptr ) ), get_talker_for( loc ) );
61566156
write_var_value( var_type::context, "id", &d, it.typeId().str() );
61576157
for( const effect_on_condition_id &eoc : eocs ) {
6158-
if( eoc->type == eoc_type::ACTIVATION ) {
6159-
eoc->activate( d );
6160-
} else {
6161-
debugmsg( "Must use an activation eoc for activation. If you don't want the effect_on_condition to happen on its own (without the item's involvement), remove the recurrence min and max. Otherwise, create a non-recurring effect_on_condition for this item with its condition and effects, then have a recurring one queue it." );
6162-
}
6158+
eoc->activate_activation_only( d, "activation", "item's involvement", "item" );
61636159
}
61646160
// Prevents crash from trying to spend charge with item removed
61656161
// NOTE: Because this section and/or calling stack does not check if the item exists in the surrounding tiles

src/magic_spell_effect.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1934,11 +1934,7 @@ void spell_effect::effect_on_condition( const spell &sp, Creature &caster,
19341934
write_var_value( var_type::context, "spell_location", &d, target_abs );
19351935
d.amend_callstack( string_format( "Spell: %s Caster: %s", sp.id().c_str(), caster.disp_name() ) );
19361936
effect_on_condition_id eoc = effect_on_condition_id( sp.effect_data() );
1937-
if( eoc->type == eoc_type::ACTIVATION ) {
1938-
eoc->activate( d );
1939-
} else {
1940-
debugmsg( "Must use an activation eoc for a spell. If you don't want the effect_on_condition to happen on its own (without the spell being cast), remove the recurrence min and max. Otherwise, create a non-recurring effect_on_condition for this spell with its condition and effects, then have a recurring one queue it." );
1941-
}
1937+
eoc->activate_activation_only( d, "a spell", "spell being cast", "spell" );
19421938
}
19431939
}
19441940

src/martialarts.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,11 +1304,8 @@ void martialart::activate_eocs( Character &u,
13041304
{
13051305
for( const effect_on_condition_id &eoc : eocs ) {
13061306
dialogue d( get_talker_for( u ), nullptr );
1307-
if( eoc->type == eoc_type::ACTIVATION ) {
1308-
eoc->activate( d );
1309-
} else {
1310-
debugmsg( "Must use an activation eoc for a martial art activation. If you don't want the effect_on_condition to happen on its own (without the martial art being activated), remove the recurrence min and max. Otherwise, create a non-recurring effect_on_condition for this martial art with its condition and effects, then have a recurring one queue it." );
1311-
}
1307+
eoc->activate_activation_only( d, "a martial art activation", "martial art being activated",
1308+
"martial art" );
13121309
}
13131310
}
13141311

src/melee.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,11 +1798,8 @@ void Character::perform_technique( const ma_technique &technique, Creature &t,
17981798

17991799
for( const effect_on_condition_id &eoc : technique.eocs ) {
18001800
dialogue d( get_talker_for( *this ), get_talker_for( t ) );
1801-
if( eoc->type == eoc_type::ACTIVATION ) {
1802-
eoc->activate( d );
1803-
} else {
1804-
debugmsg( "Must use an activation eoc for a technique activation. If you don't want the effect_on_condition to happen on its own (without the technique being activated), remove the recurrence min and max. Otherwise, create a non-recurring effect_on_condition for this technique with its condition and effects, then have a recurring one queue it." );
1805-
}
1801+
eoc->activate_activation_only( d, "a technique activation", "technique being activated",
1802+
"technique" );
18061803
}
18071804
}
18081805

0 commit comments

Comments
 (0)