From 0601ad03adaf0264ed6b4188d5f6443a415f0ff4 Mon Sep 17 00:00:00 2001 From: Fris0uman Date: Sat, 28 Nov 2020 13:46:17 +0100 Subject: [PATCH 1/7] Hyper-metabolism rework --- data/json/mutations/mutations.json | 23 +++++++++++++++++-- src/character.h | 3 +-- src/consumption.cpp | 37 ------------------------------ 3 files changed, 22 insertions(+), 41 deletions(-) diff --git a/data/json/mutations/mutations.json b/data/json/mutations/mutations.json index 544b8d198db89..3f97fcd114858 100644 --- a/data/json/mutations/mutations.json +++ b/data/json/mutations/mutations.json @@ -3279,13 +3279,32 @@ "id": "EATHEALTH", "name": { "str": "Hyper-Metabolism" }, "points": 15, - "description": "You metabolize nutrients so rapidly that you can convert food directly into useful tissue. Excess nutrition will convert to HP, rather than being wasted. Activate to skip prompt for overeating.", + "description": "Your particular metabolism allows you to burn calories at a prodigious rate to regenerate tissues in a matter of minutes, this is however a very wastefull process. Activate to start healing.", "prereqs": [ "HUNGER3" ], "types": [ "METABOLISM" ], "threshreq": [ "THRESH_CHIMERA" ], "category": [ "CHIMERA" ], "valid": false, - "active": true + "active": true, + "transform": { + "target": "EATHEALTH_active", + "msg_transform": "Your hyper-metabolism starts burning up calories.", + "active": true, + "moves": 0 + } + }, + { + "type": "mutation", + "id": "EATHEALTH_active", + "name": { "str": "Hyper-Metabolism: burning" }, + "description": "You're burning calories like crazy to heal your wounds.", + "copy-from": "EATHEALTH", + "cost": 3, + "time": 1, + "hunger": true, + "healing_awake": 300.0, + "healing_resting": 350.0, + "transform": { "target": "EATHEALTH", "msg_transform": "Your hyper-metabolism slows down.", "active": false, "moves": 0 } }, { "type": "mutation", diff --git a/src/character.h b/src/character.h index 12c5313497681..dd065c616fa72 100644 --- a/src/character.h +++ b/src/character.h @@ -471,8 +471,7 @@ class Character : public Creature, public visitable virtual int get_hunger() const; virtual int get_starvation() const; virtual int get_thirst() const; - /** Gets character's minimum hunger and thirst */ - int stomach_capacity() const; + std::pair get_thirst_description() const; std::pair get_hunger_description() const; std::pair get_fatigue_description() const; diff --git a/src/consumption.cpp b/src/consumption.cpp index f9e6d66a14fae..cf38cfec4da6e 100644 --- a/src/consumption.cpp +++ b/src/consumption.cpp @@ -143,23 +143,6 @@ static const std::map plut_charges = { { itype_id( "plut_slurry" ), PLUTONIUM_CHARGES / 2 } }; -int Character::stomach_capacity() const -{ - if( has_trait( trait_GIZZARD ) ) { - return 0; - } - - if( has_active_mutation( trait_HIBERNATE ) ) { - return -620; - } - - if( has_trait( trait_GOURMAND ) || has_trait( trait_HIBERNATE ) ) { - return -60; - } - - return -20; -} - // TODO: Move pizza scraping here. static int compute_default_effective_kcal( const item &comest, const Character &you, const cata::flat_set &extra_flags = {} ) @@ -1342,8 +1325,6 @@ bool Character::consume_effects( item &food ) mod_fatigue( nutr ); } } - // TODO: remove this - int capacity = stomach_capacity(); // Moved here and changed a bit - it was too complex // Incredibly minor stuff like this shouldn't require complexity if( !is_npc() && has_trait( trait_SLIMESPAWNER ) && @@ -1365,24 +1346,6 @@ bool Character::consume_effects( item &food ) add_msg_if_player( m_good, _( "hey, you look like me! let's work together!" ) ); } - // Last thing that happens before capping hunger - if( get_hunger() < capacity && has_trait( trait_EATHEALTH ) ) { - int excess_food = capacity - get_hunger(); - add_msg_player_or_npc( _( "You feel the %s filling you out." ), - _( " looks better after eating the %s." ), - food.tname() ); - // Guaranteed 1 HP healing, no matter what. You're welcome. ;-) - if( excess_food <= 5 ) { - healall( 1 ); - } else { - // Straight conversion, except it's divided amongst all your body parts. - healall( excess_food /= 5 ); - } - - // Note: We want this here to prevent "you can't finish this" messages - set_hunger( capacity ); - } - nutrients food_nutrients = compute_effective_nutrients( food ); const units::volume water_vol = ( food.get_comestible()->quench > 0 ) ? food.get_comestible()->quench * From 60365c82c1db3bffe2277869e785217f57757c92 Mon Sep 17 00:00:00 2001 From: Fris0uman Date: Sat, 28 Nov 2020 14:30:43 +0100 Subject: [PATCH 2/7] missing space --- data/json/mutations/mutations.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/json/mutations/mutations.json b/data/json/mutations/mutations.json index 3f97fcd114858..b8800811fc39a 100644 --- a/data/json/mutations/mutations.json +++ b/data/json/mutations/mutations.json @@ -3279,7 +3279,7 @@ "id": "EATHEALTH", "name": { "str": "Hyper-Metabolism" }, "points": 15, - "description": "Your particular metabolism allows you to burn calories at a prodigious rate to regenerate tissues in a matter of minutes, this is however a very wastefull process. Activate to start healing.", + "description": "Your particular metabolism allows you to burn calories at a prodigious rate to regenerate tissues in a matter of minutes, this is however a very wastefull process. Activate to start healing.", "prereqs": [ "HUNGER3" ], "types": [ "METABOLISM" ], "threshreq": [ "THRESH_CHIMERA" ], From c5835bc6eb722b18d930a7e674bf86c1d53164f6 Mon Sep 17 00:00:00 2001 From: Fris0uman <41293484+Fris0uman@users.noreply.github.com> Date: Sat, 28 Nov 2020 19:43:50 +0100 Subject: [PATCH 3/7] Update data/json/mutations/mutations.json Co-authored-by: LaVeyanFiend <51099123+LaVeyanFiend@users.noreply.github.com> --- data/json/mutations/mutations.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/json/mutations/mutations.json b/data/json/mutations/mutations.json index b8800811fc39a..a973fc5a587c3 100644 --- a/data/json/mutations/mutations.json +++ b/data/json/mutations/mutations.json @@ -3279,7 +3279,7 @@ "id": "EATHEALTH", "name": { "str": "Hyper-Metabolism" }, "points": 15, - "description": "Your particular metabolism allows you to burn calories at a prodigious rate to regenerate tissues in a matter of minutes, this is however a very wastefull process. Activate to start healing.", + "description": "Your particular metabolism allows you to burn calories at a prodigious rate to regenerate tissues in a matter of minutes, this is however a very wasteful process. Activate to start healing.", "prereqs": [ "HUNGER3" ], "types": [ "METABOLISM" ], "threshreq": [ "THRESH_CHIMERA" ], From 15c7471fe658bb20dfc6a9a9869e68ffa5761d84 Mon Sep 17 00:00:00 2001 From: Fris0uman Date: Sun, 29 Nov 2020 11:31:17 +0100 Subject: [PATCH 4/7] Rework suffer_mutation_power --- src/character.h | 9 ++++++-- src/mutation.cpp | 26 ++++++++++++++++++++++ src/suffer.cpp | 58 ++++++++++++++++++++++-------------------------- 3 files changed, 60 insertions(+), 33 deletions(-) diff --git a/src/character.h b/src/character.h index dd065c616fa72..bb0e9ec7b88fb 100644 --- a/src/character.h +++ b/src/character.h @@ -1151,6 +1151,11 @@ class Character : public Creature, public visitable void mutation_loss_effect( const trait_id &mut ); bool has_active_mutation( const trait_id &b ) const; + + int get_cost_timer( const trait_id &mut_id ) const; + void set_cost_timer( const trait_id &mut, int set ); + void mod_cost_timer( const trait_id &mut, int mod ); + /** Picks a random valid mutation and gives it to the Character, possibly removing/changing others along the way */ void mutate(); /** Returns true if the player doesn't have the mutation or a conflicting one and it complies with the force typing */ @@ -2753,8 +2758,8 @@ class Character : public Creature, public visitable std::map bodypart_exposure(); private: /** suffer() subcalls */ - void suffer_water_damage( const mutation_branch &mdata ); - void suffer_mutation_power( const mutation_branch &mdata, Character::trait_data &tdata ); + void suffer_water_damage( const trait_id &mut_id ); + void suffer_mutation_power( const trait_id &mut_id ); void suffer_while_underwater(); void suffer_from_addictions(); void suffer_while_awake( int current_stim ); diff --git a/src/mutation.cpp b/src/mutation.cpp index e3fbfe8c77cd9..bfa91bd11a74c 100644 --- a/src/mutation.cpp +++ b/src/mutation.cpp @@ -499,6 +499,32 @@ bool Character::has_active_mutation( const trait_id &b ) const return iter != my_mutations.end() && iter->second.powered; } +int Character::get_cost_timer( const trait_id &mut ) const +{ + const auto iter = my_mutations.find( mut ); + if( iter != my_mutations.end() ) { + return iter->second.charge; + } else { + debugmsg( "Tried to get cost timer of %s but doesn't have this mutation.", mut.c_str() ); + } + return 0; +} + +void Character::set_cost_timer( const trait_id &mut, int set ) +{ + const auto iter = my_mutations.find( mut ); + if( iter != my_mutations.end() ) { + iter->second.charge = set; + } else { + debugmsg( "Tried to set cost timer of %s but doesn't have this mutation.", mut.c_str() ); + } +} + +void Character::mod_cost_timer( const trait_id &mut, int mod ) +{ + set_cost_timer( mut, get_cost_timer( mut ) + mod ); +} + bool Character::is_category_allowed( const std::vector &category ) const { bool allowed = false; diff --git a/src/suffer.cpp b/src/suffer.cpp index acfef068d5410..05508f09c9f06 100644 --- a/src/suffer.cpp +++ b/src/suffer.cpp @@ -174,11 +174,11 @@ static float addiction_scaling( float at_min, float at_max, float add_lvl ) return lerp( at_min, at_max, ( add_lvl - MIN_ADDICTION_LEVEL ) / MAX_ADDICTION_LEVEL ); } -void Character::suffer_water_damage( const mutation_branch &mdata ) +void Character::suffer_water_damage( const trait_id &mut_id ) { for( const std::pair &elem : get_body() ) { const float wetness_percentage = elem.second.get_wetness_percentage(); - const int dmg = mdata.weakness_to_water * wetness_percentage; + const int dmg = mut_id->weakness_to_water * wetness_percentage; if( dmg > 0 ) { apply_damage( nullptr, elem.first, dmg ); add_msg_player_or_npc( m_bad, _( "Your %s is damaged by the water." ), @@ -193,50 +193,48 @@ void Character::suffer_water_damage( const mutation_branch &mdata ) } } -void Character::suffer_mutation_power( const mutation_branch &mdata, - Character::trait_data &tdata ) +void Character::suffer_mutation_power( const trait_id &mut_id ) { - if( tdata.powered && tdata.charge > 0 ) { - // Already-on units just lose a bit of charge - tdata.charge--; + if( get_cost_timer( mut_id ) > 0 ) { + // Not ready to consume cost yet, the timer ticks on + mod_cost_timer( mut_id, -1 ); } else { - // Not-on units, or those with zero charge, have to pay the power cost - if( mdata.cooldown > 0 ) { - tdata.powered = true; - tdata.charge = mdata.cooldown - 1; + // Ready to consume cost: pay the power cost and reset timer + if( mut_id->cooldown > 0 ) { + set_cost_timer( mut_id, mut_id->cooldown - 1 ); } - if( mdata.hunger ) { + if( mut_id->hunger ) { // does not directly modify hunger, but burns kcal - mod_stored_nutr( mdata.cost ); + mod_stored_nutr( mut_id->cost ); if( get_bmi() < character_weight_category::underweight ) { add_msg_if_player( m_warning, _( "You're too malnourished to keep your %s going." ), - mdata.name() ); - tdata.powered = false; + mut_id->name() ); + deactivate_mutation( mut_id ); } } - if( mdata.thirst ) { - mod_thirst( mdata.cost ); + if( mut_id->thirst ) { + mod_thirst( mut_id->cost ); // Well into Dehydrated if( get_thirst() >= 260 ) { add_msg_if_player( m_warning, _( "You're too dehydrated to keep your %s going." ), - mdata.name() ); - tdata.powered = false; + mut_id->name() ); + deactivate_mutation( mut_id ); } } - if( mdata.fatigue ) { - mod_fatigue( mdata.cost ); + if( mut_id->fatigue ) { + mod_fatigue( mut_id->cost ); // Exhausted if( get_fatigue() >= fatigue_levels::EXHAUSTED ) { add_msg_if_player( m_warning, _( "You're too exhausted to keep your %s going." ), - mdata.name() ); - tdata.powered = false; + mut_id->name() ); + deactivate_mutation( mut_id ); } } - if( !tdata.powered ) { - apply_mods( mdata.id, false ); + if( !has_active_mutation( mut_id ) ) { + apply_mods( mut_id, false ); } } } @@ -1529,14 +1527,12 @@ void Character::suffer() process_bionic( i ); } - for( std::pair &mut : my_mutations ) { - const mutation_branch &mdata = mut.first.obj(); + for( const trait_id &mut_id : get_mutations() ) { if( calendar::once_every( 1_minutes ) ) { - suffer_water_damage( mdata ); + suffer_water_damage( mut_id ); } - Character::trait_data &tdata = mut.second; - if( tdata.powered ) { - suffer_mutation_power( mdata, tdata ); + if( has_active_mutation( mut_id ) ) { + suffer_mutation_power( mut_id ); } } From 5e923ea0152b95c016142894d8d363bf188399c2 Mon Sep 17 00:00:00 2001 From: Fris0uman Date: Sun, 29 Nov 2020 11:38:10 +0100 Subject: [PATCH 5/7] Don't pay mutation cost if you can't --- src/suffer.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/suffer.cpp b/src/suffer.cpp index 05508f09c9f06..ccb9908280b4f 100644 --- a/src/suffer.cpp +++ b/src/suffer.cpp @@ -204,33 +204,36 @@ void Character::suffer_mutation_power( const trait_id &mut_id ) set_cost_timer( mut_id, mut_id->cooldown - 1 ); } if( mut_id->hunger ) { - // does not directly modify hunger, but burns kcal - mod_stored_nutr( mut_id->cost ); if( get_bmi() < character_weight_category::underweight ) { add_msg_if_player( m_warning, _( "You're too malnourished to keep your %s going." ), mut_id->name() ); deactivate_mutation( mut_id ); + } else { + // does not directly modify hunger, but burns kcal + mod_stored_nutr( mut_id->cost ); } } if( mut_id->thirst ) { - mod_thirst( mut_id->cost ); // Well into Dehydrated if( get_thirst() >= 260 ) { add_msg_if_player( m_warning, _( "You're too dehydrated to keep your %s going." ), mut_id->name() ); deactivate_mutation( mut_id ); + } else { + mod_thirst( mut_id->cost ); } } if( mut_id->fatigue ) { - mod_fatigue( mut_id->cost ); // Exhausted if( get_fatigue() >= fatigue_levels::EXHAUSTED ) { add_msg_if_player( m_warning, _( "You're too exhausted to keep your %s going." ), mut_id->name() ); deactivate_mutation( mut_id ); + } else { + mod_fatigue( mut_id->cost ); } } if( !has_active_mutation( mut_id ) ) { From a964cfeededfd21e1c641b3979114cda68a13b1a Mon Sep 17 00:00:00 2001 From: Fris0uman Date: Sun, 29 Nov 2020 11:38:31 +0100 Subject: [PATCH 6/7] Remove unnecessary stat update --- src/suffer.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/suffer.cpp b/src/suffer.cpp index ccb9908280b4f..e42c831a6fa60 100644 --- a/src/suffer.cpp +++ b/src/suffer.cpp @@ -236,9 +236,6 @@ void Character::suffer_mutation_power( const trait_id &mut_id ) mod_fatigue( mut_id->cost ); } } - if( !has_active_mutation( mut_id ) ) { - apply_mods( mut_id, false ); - } } } From 5eae2fb8f4a4a5e93ec1e08e7e1447e58249dc4f Mon Sep 17 00:00:00 2001 From: Fris0uman Date: Sun, 29 Nov 2020 11:56:38 +0100 Subject: [PATCH 7/7] Lower cost to 9 kcal/s instead of 26 kcal/s --- data/json/mutations/mutations.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/json/mutations/mutations.json b/data/json/mutations/mutations.json index a973fc5a587c3..092e661c7cca2 100644 --- a/data/json/mutations/mutations.json +++ b/data/json/mutations/mutations.json @@ -3299,7 +3299,7 @@ "name": { "str": "Hyper-Metabolism: burning" }, "description": "You're burning calories like crazy to heal your wounds.", "copy-from": "EATHEALTH", - "cost": 3, + "cost": 1, "time": 1, "hunger": true, "healing_awake": 300.0,