Skip to content

Commit

Permalink
change crossed_threshold() scope and test_crossing_threshold() parame…
Browse files Browse the repository at this point in the history
…ter to Character (#34761)

* change scope of crossed_threshold()

* moved crossed_threshold to character.cpp

* change parameter of test_crossing_threshold to Character

* change "p" to "guy"
  • Loading branch information
KorGgenT authored and ZhilkinSerg committed Oct 16, 2019
1 parent e07aaac commit 94104c6
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 38 deletions.
10 changes: 10 additions & 0 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4684,6 +4684,16 @@ void Character::on_hurt( Creature *source, bool disturb /*= true*/ )
}
}

bool Character::crossed_threshold() const
{
for( const std::pair<trait_id, Character::trait_data> &mut : my_mutations ) {
if( mut.first->threshold ) {
return true;
}
}
return false;
}

void Character::spores()
{
fungal_effects fe( *g, g->m );
Expand Down
4 changes: 4 additions & 0 deletions src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,10 @@ class Character : public Creature, public visitable<Character>
*/
void add_traits();
void add_traits( points_left &points );
/** Returns true if the player has crossed a mutation threshold
* Player can only cross one mutation threshold.
*/
bool crossed_threshold() const;

// --------------- Values ---------------
std::string name;
Expand Down
46 changes: 23 additions & 23 deletions src/mutation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1339,10 +1339,10 @@ mutagen_attempt mutagen_common_checks( player &p, const item &it, bool strong,
return mutagen_attempt( true, 0 );
}

void test_crossing_threshold( player &p, const mutation_category_trait &m_category )
void test_crossing_threshold( Character &guy, const mutation_category_trait &m_category )
{
// Threshold-check. You only get to cross once!
if( p.crossed_threshold() ) {
if( guy.crossed_threshold() ) {
return;
}

Expand All @@ -1355,11 +1355,11 @@ void test_crossing_threshold( player &p, const mutation_category_trait &m_catego
std::string mutation_category = m_category.id;
int total = 0;
for( const auto &iter : mutation_category_trait::get_all() ) {
total += p.mutation_category_level[ iter.first ];
total += guy.mutation_category_level[ iter.first ];
}
// Threshold-breaching
const std::string &primary = p.get_highest_category();
int breach_power = p.mutation_category_level[primary];
const std::string &primary = guy.get_highest_category();
int breach_power = guy.mutation_category_level[primary];
// Only if you were pushing for more in your primary category.
// You wanted to be more like it and less human.
// That said, you're required to have hit third-stage dreams first.
Expand All @@ -1374,33 +1374,33 @@ void test_crossing_threshold( player &p, const mutation_category_trait &m_catego
}
int breacher = breach_power + booster;
if( x_in_y( breacher, total ) ) {
p.add_msg_if_player( m_good,
_( "Something strains mightily for a moment... and then... you're... FREE!" ) );
p.set_mutation( mutation_thresh );
g->events().send<event_type::crosses_mutation_threshold>( p.getID(), m_category.id );
guy.add_msg_if_player( m_good,
_( "Something strains mightily for a moment... and then... you're... FREE!" ) );
guy.set_mutation( mutation_thresh );
g->events().send<event_type::crosses_mutation_threshold>( guy.getID(), m_category.id );
// Manually removing Carnivore, since it tends to creep in
// This is because carnivore is a prerequisite for the
// predator-style post-threshold mutations.
if( mutation_category == "URSINE" && p.has_trait( trait_CARNIVORE ) ) {
p.unset_mutation( trait_CARNIVORE );
p.add_msg_if_player( _( "Your appetite for blood fades." ) );
if( mutation_category == "URSINE" && guy.has_trait( trait_CARNIVORE ) ) {
guy.unset_mutation( trait_CARNIVORE );
guy.add_msg_if_player( _( "Your appetite for blood fades." ) );
}
}
} else if( p.has_trait( trait_NOPAIN ) ) {
} else if( guy.has_trait( trait_NOPAIN ) ) {
//~NOPAIN is a post-Threshold trait, so you shouldn't
//~legitimately have it and get here!
p.add_msg_if_player( m_bad, _( "You feel extremely Bugged." ) );
guy.add_msg_if_player( m_bad, _( "You feel extremely Bugged." ) );
} else if( breach_power > 100 ) {
p.add_msg_if_player( m_bad, _( "You stagger with a piercing headache!" ) );
p.mod_pain_noresist( 8 );
p.add_effect( effect_stunned, rng( 3_turns, 5_turns ) );
guy.add_msg_if_player( m_bad, _( "You stagger with a piercing headache!" ) );
guy.mod_pain_noresist( 8 );
guy.add_effect( effect_stunned, rng( 3_turns, 5_turns ) );
} else if( breach_power > 80 ) {
p.add_msg_if_player( m_bad,
_( "Your head throbs with memories of your life, before all this..." ) );
p.mod_pain_noresist( 6 );
p.add_effect( effect_stunned, rng( 2_turns, 4_turns ) );
guy.add_msg_if_player( m_bad,
_( "Your head throbs with memories of your life, before all this..." ) );
guy.mod_pain_noresist( 6 );
guy.add_effect( effect_stunned, rng( 2_turns, 4_turns ) );
} else if( breach_power > 60 ) {
p.add_msg_if_player( m_bad, _( "Images of your past life flash before you." ) );
p.add_effect( effect_stunned, rng( 2_turns, 3_turns ) );
guy.add_msg_if_player( m_bad, _( "Images of your past life flash before you." ) );
guy.add_effect( effect_stunned, rng( 2_turns, 3_turns ) );
}
}
2 changes: 1 addition & 1 deletion src/mutation.h
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,6 @@ struct mutagen_attempt {
mutagen_attempt mutagen_common_checks( player &p, const item &it, bool strong,
mutagen_technique technique );

void test_crossing_threshold( player &p, const mutation_category_trait &m_category );
void test_crossing_threshold( Character &guy, const mutation_category_trait &m_category );

#endif
10 changes: 0 additions & 10 deletions src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2016,16 +2016,6 @@ bool player::has_same_type_trait( const trait_id &flag ) const
return false;
}

bool player::crossed_threshold() const
{
for( auto &mut : my_mutations ) {
if( mut.first->threshold ) {
return true;
}
}
return false;
}

bool player::purifiable( const trait_id &flag ) const
{
return flag->purifiable;
Expand Down
4 changes: 0 additions & 4 deletions src/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,6 @@ class player : public Character
bool has_higher_trait( const trait_id &flag ) const;
/** Returns true if the player has a trait that shares a type with the entered trait */
bool has_same_type_trait( const trait_id &flag ) const;
/** Returns true if the player has crossed a mutation threshold
* Player can only cross one mutation threshold.
*/
bool crossed_threshold() const;
/** Returns true if the entered trait may be purified away
* Defaults to true
*/
Expand Down

0 comments on commit 94104c6

Please sign in to comment.