Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Toggle bionics/deactivate mutations causes bonus stats ignored until next turn #78090

Merged
merged 6 commits into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/bionics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1174,9 +1174,7 @@ bool Character::activate_bionic( bionic &bio, bool eff_only, bool *close_bionics
}
}
bio_flag_cache.clear();
// Recalculate stats (strength, mods from pain etc.) that could have been affected
calc_encumbrance();
reset();

// Also reset crafting inventory cache if this bionic spawned a fake item
if( bio.has_weapon() || !bio.info().passive_pseudo_items.empty() ||
Expand Down Expand Up @@ -1272,9 +1270,7 @@ bool Character::deactivate_bionic( bionic &bio, bool eff_only )
}
}

// Recalculate stats (strength, mods from pain etc.) that could have been affected
calc_encumbrance();
reset();
if( !bio.id->enchantments.empty() ) {
recalculate_enchantment_cache();
}
Expand Down
4 changes: 0 additions & 4 deletions src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -1541,16 +1541,12 @@ class Character : public Creature, public visitable
bool made_of_any( const std::set<material_id> &ms ) const override;

private:
/** Retrieves a stat mod of a mutation. */
int get_mod( const trait_id &mut, const std::string &arg ) const;
/** Applies skill-based boosts to stats **/
void apply_skill_boost();
protected:

void on_move( const tripoint_abs_ms &old_pos ) override;
void do_skill_rust();
/** Applies stat mods to character. */
void apply_mods( const trait_id &mut, bool add_remove );

/** Applies encumbrance from mutations and bionics only */
void mut_cbm_encumb( std::map<bodypart_id, encumbrance_data> &vals ) const;
Expand Down
34 changes: 2 additions & 32 deletions src/mutation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,32 +444,6 @@ bool reflex_activation_data::is_trigger_true( Character &guy ) const
return trigger( d );
}

int Character::get_mod( const trait_id &mut, const std::string &arg ) const
{
const auto &mod_data = mut->mods;
int ret = 0;
auto found = mod_data.find( std::make_pair( false, arg ) );
if( found != mod_data.end() ) {
ret += found->second;
}
return ret;
}

void Character::apply_mods( const trait_id &mut, bool add_remove )
{
int sign = add_remove ? 1 : -1;
int str_change = get_mod( mut, "STR" );
str_max += sign * str_change;
per_max += sign * get_mod( mut, "PER" );
dex_max += sign * get_mod( mut, "DEX" );
int_max += sign * get_mod( mut, "INT" );

reset_stats();
if( str_change != 0 ) {
recalc_hp();
}
}

bool mutation_branch::conflicts_with_item( const item &it ) const
{
if( allow_soft_gear && it.is_soft() ) {
Expand Down Expand Up @@ -575,9 +549,8 @@ void Character::mutation_effect( const trait_id &mut, const bool worn_destroyed_
{
if( mut == trait_GLASSJAW ) {
recalc_hp();
} else {
apply_mods( mut, true );
}
reset();

recalculate_size();

Expand Down Expand Up @@ -655,9 +628,8 @@ void Character::mutation_loss_effect( const trait_id &mut )
{
if( mut == trait_GLASSJAW ) {
recalc_hp();
} else {
apply_mods( mut, false );
}
reset();

recalculate_size();

Expand Down Expand Up @@ -997,8 +969,6 @@ void Character::deactivate_mutation( const trait_id &mut )
my_mutations[mut].powered = false;
trait_flag_cache.clear();

// Handle stat changes from deactivation
apply_mods( mut, false );
recalc_sight_limits();
const mutation_branch &mdata = mut.obj();
if( mdata.transform ) {
Expand Down
3 changes: 0 additions & 3 deletions src/mutation.h
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,6 @@ struct mutation_branch {
std::set<sub_bodypart_str_id> remove_rigid_subparts;
// item flags that allow wearing gear even if its body part is restricted
std::set<flag_id> allowed_items;
// Mutation stat mods
/** Key pair is <active: bool, mod type: "STR"> */
std::unordered_map<std::pair<bool, std::string>, int, cata::tuple_hash> mods;
std::map<bodypart_str_id, resistances> armor; // Modifiers to protection values
std::vector<itype_id> integrated_armor; // Armor pseudo-items that are put on by this mutation
std::vector<matype_id>
Expand Down
Loading