From 7db08ba48145aeb6b8e24b919aef6580ae550242 Mon Sep 17 00:00:00 2001 From: scarf Date: Thu, 20 Apr 2023 18:07:47 +0900 Subject: [PATCH 1/4] feat: allow installing non-sterile CBM when `Infection Immune` --- src/game_inventory.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/game_inventory.cpp b/src/game_inventory.cpp index c75444b26544..a603c9a48119 100644 --- a/src/game_inventory.cpp +++ b/src/game_inventory.cpp @@ -78,6 +78,7 @@ static const trait_id trait_DEBUG_BIONICS( "DEBUG_BIONICS" ); static const trait_id trait_NOPAIN( "NOPAIN" ); static const trait_id trait_SAPROPHAGE( "SAPROPHAGE" ); static const trait_id trait_SAPROVORE( "SAPROVORE" ); +static const trait_id trait_INFRESIST( "INFRESIST" ); static const std::string flag_ALLOWS_REMOTE_USE( "ALLOWS_REMOTE_USE" ); static const std::string flag_FILTHY( "FILTHY" ); @@ -1881,7 +1882,7 @@ class bionic_install_preset: public inventory_selector_preset const itype *itemtype = it->type; const bionic_id &bid = itemtype->bionic->id; - if( it->has_fault( fault_bionic_nonsterile ) ) { + if( it->has_fault( fault_bionic_nonsterile ) && !p.has_trait( trait_INFRESIST ) ) { // NOLINTNEXTLINE(cata-text-style): single space after the period for symmetry return _( "/!\\ CBM is not sterile. /!\\ Please use autoclave or other methods to sterilize." ); } else if( pa.has_bionic( bid ) ) { From 2809d22e49771688a5af81080e3b633de60de041 Mon Sep 17 00:00:00 2001 From: scarf Date: Thu, 20 Apr 2023 21:05:42 +0900 Subject: [PATCH 2/4] refactor: use `std::accumulate` over for loop --- src/game_inventory.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/game_inventory.cpp b/src/game_inventory.cpp index a603c9a48119..1598bd56aed5 100644 --- a/src/game_inventory.cpp +++ b/src/game_inventory.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -1792,7 +1793,6 @@ static item_location autodoc_internal( player &u, player &patient, { inventory_pick_selector inv_s( u, preset ); std::string hint; - int drug_count = 0; if( !surgeon ) {//surgeon use their own anesthetic, player just need money if( patient.has_trait( trait_NOPAIN ) ) { @@ -1804,11 +1804,10 @@ static item_location autodoc_internal( player &u, player &patient, std::vector a_filter = crafting_inv.items_with( []( const item & it ) { return it.has_quality( qual_ANESTHESIA ); } ); - for( const item *anesthesia_item : a_filter ) { - if( anesthesia_item->ammo_remaining() >= 1 ) { - drug_count += anesthesia_item->ammo_remaining(); - } - } + const int drug_count = std::accumulate( a_filter.begin(), a_filter.end(), 0, + []( int sum, const item * it ) { + return sum + it->ammo_remaining(); + } ); hint = string_format( _( "Available anesthetic: %i mL" ), drug_count ); } } From 74a65a077d593d804060847b97a88477baf2843a Mon Sep 17 00:00:00 2001 From: scarf Date: Thu, 20 Apr 2023 21:06:58 +0900 Subject: [PATCH 3/4] refactor: extract duplicate if statement --- src/game_inventory.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/game_inventory.cpp b/src/game_inventory.cpp index 1598bd56aed5..18b19ea74345 100644 --- a/src/game_inventory.cpp +++ b/src/game_inventory.cpp @@ -1820,11 +1820,9 @@ static item_location autodoc_internal( player &u, player &patient, _( "\nFound bionic installation data. Affected CBMs are marked with an asterisk." ) ); } - if( uninstall ) { - inv_s.set_title( string_format( _( "Bionic removal patient: %s" ), patient.get_name() ) ); - } else { - inv_s.set_title( string_format( _( "Bionic installation patient: %s" ), patient.get_name() ) ); - } + const auto title = uninstall + ? _( "Bionic removal patient: %s" ) : _( "Bionic installation patient: %s" ); + inv_s.set_title( string_format( title, patient.get_name() ) ); inv_s.set_hint( hint ); inv_s.set_display_stats( false ); From 425ff399b9d90c23dd8e37dc17fb037f2f64ccfd Mon Sep 17 00:00:00 2001 From: scarf Date: Thu, 20 Apr 2023 21:07:49 +0900 Subject: [PATCH 4/4] feat: add description about CBM for `Infection Immune` --- 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 471eb2b662d2..9545aa56471b 100644 --- a/data/json/mutations/mutations.json +++ b/data/json/mutations/mutations.json @@ -2547,7 +2547,7 @@ "id": "INFRESIST", "name": { "str": "Infection Immune" }, "points": 1, - "description": "Your immune system is particularly good at resisting infections. Your wounds will no longer become infected, altough existing infections are still dangerous.", + "description": "Your immune system is particularly good at resisting infections. Your wounds will no longer become infected, altough existing infections are still dangerous. You will also be able to install non-sterile CBMs.", "starting_trait": true, "category": [ "TROGLOBITE", "RAT", "MEDICAL" ] },