Skip to content

Commit f80240f

Browse files
committed
Dedupe EOC activation checks and messages
1 parent 218dc92 commit f80240f

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
@@ -1585,12 +1585,8 @@ void Character::complete_craft( item &craft, const std::optional<tripoint_bub_ms
15851585
inv->restack( *this );
15861586
for( const effect_on_condition_id &eoc : making.result_eocs ) {
15871587
dialogue d( get_talker_for( *this ), nullptr );
1588-
if( eoc->type == eoc_type::ACTIVATION ) {
1589-
for( int i = 0; i < batch_size; i++ ) {
1590-
eoc->activate( d );
1591-
}
1592-
} else {
1593-
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." );
1588+
for( int i = 0; i < batch_size; i++ ) {
1589+
eoc->activate_activation_only( d, "a recipe", "crafting", "recipe" );
15941590
}
15951591
}
15961592
}

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
@@ -357,6 +357,24 @@ bool effect_on_condition::activate( dialogue &d, bool require_callstack_check )
357357
return retval;
358358
}
359359

360+
bool effect_on_condition::activate_activation_only( dialogue &d, const std::string &text1,
361+
const std::string &text2, const std::string &text3, bool require_callstack_check ) const
362+
{
363+
if( type == eoc_type::ACTIVATION ) {
364+
return activate( d, require_callstack_check );
365+
}
366+
debugmsg(
367+
"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.",
368+
text1,
369+
text2.empty() ? "" :
370+
". If you don't want the effect_on_condition to happen on its own (without the ",
371+
text2,
372+
text2.empty() ? "" : "), remove the recurrence min and max.",
373+
text3,
374+
text3.empty() ? "" : " " );
375+
return false;
376+
}
377+
360378
bool effect_on_condition::check_deactivate( const_dialogue const &d ) const
361379
{
362380
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
@@ -14447,21 +14447,13 @@ void avatar_moves( const tripoint_abs_ms &old_abs_pos, const avatar &u, const ma
1444714447
if( !past_ter->get_exit_EOC().is_null() ) {
1444814448
dialogue d( get_talker_for( get_avatar() ), nullptr );
1444914449
effect_on_condition_id eoc = cur_ter->get_exit_EOC();
14450-
if( eoc->type == eoc_type::ACTIVATION ) {
14451-
eoc->activate( d );
14452-
} else {
14453-
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." );
14454-
}
14450+
eoc->activate_activation_only( d, "OMT movement" );
1445514451
}
1445614452

1445714453
if( !cur_ter->get_entry_EOC().is_null() ) {
1445814454
dialogue d( get_talker_for( get_avatar() ), nullptr );
1445914455
effect_on_condition_id eoc = cur_ter->get_entry_EOC();
14460-
if( eoc->type == eoc_type::ACTIVATION ) {
14461-
eoc->activate( d );
14462-
} else {
14463-
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." );
14464-
}
14456+
eoc->activate_activation_only( d, "OMT movement" );
1446514457
}
1446614458

1446714459
}

src/iuse_actor.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6144,11 +6144,7 @@ std::optional<int> effect_on_conditions_actor::use( Character *p, item &it,
61446144
dialogue d( ( char_ptr == nullptr ? nullptr : get_talker_for( char_ptr ) ), get_talker_for( loc ) );
61456145
write_var_value( var_type::context, "id", &d, it.typeId().str() );
61466146
for( const effect_on_condition_id &eoc : eocs ) {
6147-
if( eoc->type == eoc_type::ACTIVATION ) {
6148-
eoc->activate( d );
6149-
} else {
6150-
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." );
6151-
}
6147+
eoc->activate_activation_only( d, "activation", "item's involvement", "item" );
61526148
}
61536149
// Prevents crash from trying to spend charge with item removed
61546150
// 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)