Skip to content

Commit b3c2bb2

Browse files
Maleclypsegithub-actions[bot]ehughsbaird
authored
Mutation selection stops at certain points (#82649)
* First step Update mutation.cpp Update mutation.cpp Update mutation.cpp Update mutation.cpp Update mutation.cpp * Count Substitute Threshold traits * Update mutation.cpp * Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update src/mutation.cpp * Update src/mutation.cpp Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update mutations.json * Update mutation.cpp * Apply suggestions from code review Co-authored-by: ehughsbaird <[email protected]> * Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update mutation.cpp * Update mutation.cpp * Update src/mutation.cpp * Update mutation.cpp * Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Apply suggestions from code review * Apply suggestions from code review * Update src/mutation.cpp * Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update src/mutation.cpp * Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update src/mutation.cpp * Apply suggestions from code review --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: ehughsbaird <[email protected]>
1 parent 0e1a964 commit b3c2bb2

File tree

4 files changed

+46
-2
lines changed

4 files changed

+46
-2
lines changed

data/json/mutations/mutations.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2206,7 +2206,9 @@
22062206
"starting_trait": true,
22072207
"cancels": [ "ROBUST", "RESTRICTED", "RESISTANT_GENETICS" ],
22082208
"valid": false,
2209-
"vitamin_rates": [ [ "instability", -60 ] ]
2209+
"vitamin_rates": [ [ "instability", -60 ] ],
2210+
"category": [ "CHIMERA" ],
2211+
"threshreq": [ "THRESH_CHIMERA" ]
22102212
},
22112213
{
22122214
"type": "mutation",
@@ -7778,6 +7780,7 @@
77787780
"purifiable": false,
77797781
"description": "Your body alters itself rapidly, and without your intervention or conscious control.",
77807782
"prereqs": [ "UNSTABLE", "MUT_JUNKIE" ],
7783+
"changes_to": [ "CHAOTIC_BAD" ],
77817784
"category": [ "CHIMERA" ]
77827785
},
77837786
{

src/character.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,22 @@ bool Character::has_martialart( const matype_id &m ) const
730730
return martial_arts_data->has_martialart( m );
731731
}
732732

733+
int Character::count_threshold_substitute_traits() const
734+
{
735+
int count = 0;
736+
for( const mutation_branch &mut : mutation_branch::get_all() ) {
737+
if( !mut.threshold_substitutes.empty() && has_trait( mut.id ) &&
738+
std::find_if( mut.threshold_substitutes.begin(), mut.threshold_substitutes.end(),
739+
[this]( const trait_id & t ) {
740+
return has_trait( t );
741+
} ) != mut.threshold_substitutes.end() ) {
742+
++count;
743+
break;
744+
}
745+
}
746+
return count;
747+
}
748+
733749
int Character::get_oxygen_max() const
734750
{
735751
return 30 + ( has_bionic( bio_synlungs ) ? 30 : 2 * str_cur );

src/character.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,8 @@ class Character : public Creature, public visitable
648648
int get_arm_str() const;
649649
// Defines distance from which CAMOUFLAGE mobs are visible
650650
int get_eff_per() const override;
651+
// Counts how many traits a character has via threshold substitution
652+
int count_threshold_substitute_traits() const;
651653

652654
// Penalty modifiers applied for ranged attacks due to low stats
653655
int ranged_dex_mod() const;

src/mutation.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ static const mutation_category_id mutation_category_ANY( "ANY" );
8787
static const trait_id trait_ARVORE_FOREST_MAPPING( "ARVORE_FOREST_MAPPING" );
8888
static const trait_id trait_BURROW( "BURROW" );
8989
static const trait_id trait_BURROWLARGE( "BURROWLARGE" );
90+
static const trait_id trait_CHAOTIC( "CHAOTIC" );
9091
static const trait_id trait_CHAOTIC_BAD( "CHAOTIC_BAD" );
9192
static const trait_id trait_ECHOLOCATION( "ECHOLOCATION" );
9293
static const trait_id trait_GASTROPOD_EXTREMITY2( "GASTROPOD_EXTREMITY2" );
@@ -1343,8 +1344,24 @@ void Character::mutate( const int &true_random_chance, bool use_vitamins )
13431344
}
13441345
if( mutate_towards( valid, cat, 2, use_vitamins ) ) {
13451346
add_msg_if_player( m_mixed, mutation_category_trait::get_category( cat ).mutagen_message() );
1347+
int sub_count = count_threshold_substitute_traits();
1348+
if( sub_count > 2 ) {
1349+
int chance = sub_count - 2;
1350+
if( !has_trait( trait_CHAOTIC ) && !has_trait( trait_CHAOTIC_BAD ) ) {
1351+
if( rng( 1, 100 ) <= chance ) {
1352+
mutate_towards( trait_CHAOTIC );
1353+
add_msg_if_player( m_bad, _( "You will mutate uncontrollably from now on!" ) );
1354+
} else if( has_trait( trait_CHAOTIC ) && !has_trait( trait_CHAOTIC_BAD ) ) {
1355+
if( rng( 1, 100 ) <= chance ) {
1356+
mutate_towards( trait_CHAOTIC_BAD );
1357+
add_msg_if_player( m_bad, _( "Your genetics have become irreparably damaged!" ) );
1358+
}
1359+
}
1360+
}
1361+
return;
1362+
}
1363+
return;
13461364
}
1347-
return;
13481365
}
13491366
} while( valid.empty() );
13501367
}
@@ -1417,6 +1434,12 @@ void Character::mutate_category( const mutation_category_id &cat )
14171434
bool Character::mutation_selector( const std::vector<trait_id> &prospective_traits,
14181435
const mutation_category_id &cat, const bool &use_vitamins )
14191436
{
1437+
if( has_trait( trait_CHAOTIC ) || has_trait( trait_CHAOTIC_BAD ) ) {
1438+
add_msg_if_player( m_bad,
1439+
_( "Your genetic degeneration prevents you from selecting a mutation directly!" ) );
1440+
return false;
1441+
}
1442+
14201443
// Setup menu
14211444
uilist mmenu;
14221445
mmenu.text =

0 commit comments

Comments
 (0)