Skip to content

Commit

Permalink
feat: show monster immunity in description (#3254)
Browse files Browse the repository at this point in the history
* feat: show monster immunity in description

* fix: describe bioproof only once

Co-authored-by: Chaosvolt <[email protected]>

* fix: use describe_flags

* perf: use string_view

* style: cmake format

---------

Co-authored-by: Chaosvolt <[email protected]>
  • Loading branch information
scarf005 and chaosvolt authored Sep 25, 2023
1 parent 1d7d3d4 commit fbcaae3
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -756,33 +756,35 @@ std::string monster::extended_description() const

using flag_description = std::pair<m_flag, std::string>;
const auto describe_flags = [this, &ss](
const std::string & format,
const std::vector<flag_description> &flags_names,
const std::string &if_empty = "" ) {
std::string_view format,
const std::vector<flag_description> &&flags_names,
std::string_view if_empty = "" ) {
std::string flag_descriptions = enumerate_as_string( flags_names.begin(),
flags_names.end(), [this]( const flag_description & fd ) {
return type->has_flag( fd.first ) ? fd.second : "";
} );
if( !flag_descriptions.empty() ) {
ss += string_format( format, flag_descriptions ) + "\n";
} else if( !if_empty.empty() ) {
ss += if_empty + "\n";
ss += if_empty;
ss += "\n";
}
};

using property_description = std::pair<bool, std::string>;
const auto describe_properties = [&ss](
const std::string & format,
std::string_view format,
const std::vector<property_description> &property_names,
const std::string &if_empty = "" ) {
std::string_view if_empty = "" ) {
std::string property_descriptions = enumerate_as_string( property_names.begin(),
property_names.end(), []( const property_description & pd ) {
return pd.first ? pd.second : "";
} );
if( !property_descriptions.empty() ) {
ss += string_format( format, property_descriptions ) + "\n";
} else if( !if_empty.empty() ) {
ss += if_empty + "\n";
ss += if_empty;
ss += "\n";
}
};

Expand All @@ -792,6 +794,15 @@ std::string monster::extended_description() const
{m_flag::MF_SMELLS, pgettext( "Smell as sense", "smell" )},
}, _( "It doesn't have senses." ) );

describe_flags( _( "It is immune to %s." ), {
{m_flag::MF_FIREPROOF, pgettext( "Fire as immunity", "fire" )},
{m_flag::MF_COLDPROOF, pgettext( "Cold as immunity", "cold" )},
{m_flag::MF_ACIDPROOF, pgettext( "Acid as immunity", "acid" )},
{m_flag::MF_STUN_IMMUNE, pgettext( "Stun as immunity", "stun" )},
{m_flag::MF_SLUDGEPROOF, pgettext( "Sludge as immunity", "sludge" )},
{m_flag::MF_BIOPROOF, pgettext( "Biological hazards as immunity", "biohazards" )},
} );

describe_properties( _( "It can %s." ), {
{swims(), pgettext( "Swim as an action", "swim" )},
{flies(), pgettext( "Fly as an action", "fly" )},
Expand Down

0 comments on commit fbcaae3

Please sign in to comment.