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

feat: show monster immunity in description #3254

Merged
merged 5 commits into from
Sep 25, 2023
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
1 change: 0 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ add_custom_command(
${CMAKE_SOURCE_DIR}/src/version.cmake
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})


# Build tiles version if requested
if (TILES)
setup_library(cataclysm-tiles-common)
Expand Down
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
Loading