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

Revise durability messages again, showing before/after transitions #30183

Merged
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
75 changes: 45 additions & 30 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2945,37 +2945,9 @@ std::string item::tname( unsigned int quantity, bool with_prefix, unsigned int t

if( ( damage() != 0 || ( get_option<bool>( "ITEM_HEALTH_BAR" ) && is_armor() ) ) && !is_null() &&
with_prefix ) {
if( damage() < 0 ) {
if( get_option<bool>( "ITEM_HEALTH_BAR" ) ) {
damtext = "<color_" + string_from_color( damage_color() ) + ">" + damage_symbol() + " </color>";
truncate_override = damtext.length() - 3;
} else if( is_gun() ) {
damtext = pgettext( "damage adjective", "accurized " );
} else {
damtext = pgettext( "damage adjective", "reinforced " );
}
} else if( typeId() == "corpse" ) {
if( damage() > 0 ) {
switch( damage_level( 4 ) ) {
case 1:
damtext = pgettext( "damage adjective", "bruised " );
break;
case 2:
damtext = pgettext( "damage adjective", "damaged " );
break;
case 3:
damtext = pgettext( "damage adjective", "mangled " );
break;
default:
damtext = pgettext( "damage adjective", "pulped " );
break;
}
}
} else if( get_option<bool>( "ITEM_HEALTH_BAR" ) ) {
damtext = "<color_" + string_from_color( damage_color() ) + ">" + damage_symbol() + " </color>";
damtext = durability_indicator();
if( get_option<bool>( "ITEM_HEALTH_BAR" ) ) {
truncate_override = damtext.length() - 3;
} else {
damtext = string_format( "%s ", get_base_material().dmg_adj( damage_level( 4 ) ) );
}
}
if( !faults.empty() ) {
Expand Down Expand Up @@ -4488,6 +4460,49 @@ std::string item::damage_symbol() const
}
}

std::string item::durability_indicator( bool include_intact ) const
{
std::string outputstring;

if( damage() < 0 ) {
if( get_option<bool>( "ITEM_HEALTH_BAR" ) ) {
outputstring = "<color_" + string_from_color( damage_color() ) + ">" + damage_symbol() +
" </color>";
} else if( is_gun() ) {
outputstring = pgettext( "damage adjective", "accurized " );
} else {
outputstring = pgettext( "damage adjective", "reinforced " );
}
} else if( typeId() == "corpse" ) {
if( damage() > 0 ) {
switch( damage_level( 4 ) ) {
case 1:
outputstring = pgettext( "damage adjective", "bruised " );
break;
case 2:
outputstring = pgettext( "damage adjective", "damaged " );
break;
case 3:
outputstring = pgettext( "damage adjective", "mangled " );
break;
default:
outputstring = pgettext( "damage adjective", "pulped " );
break;
}
}
} else if( get_option<bool>( "ITEM_HEALTH_BAR" ) ) {
outputstring = "<color_" + string_from_color( damage_color() ) + ">" + damage_symbol() +
" </color>";
} else {
outputstring = string_format( "%s ", get_base_material().dmg_adj( damage_level( 4 ) ) );
if( include_intact && outputstring == " " ) {
outputstring = _( "fully intact " );
}
}

return outputstring;
}

const std::set<itype_id> &item::repaired_with() const
{
static std::set<itype_id> no_repair;
Expand Down
8 changes: 8 additions & 0 deletions src/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,14 @@ class item : public visitable<item>
/** Provide prefix symbol for UI display dependent upon current item damage level */
std::string damage_symbol() const;

/**
* Provides a prefix for the durability state of the item. with ITEM_HEALTH_BAR enabled,
* returns a symbol with color tag already applied. Otherwise, returns an adjective.
* if include_intact is true, this provides a string for the corner case of a player
* with ITEM_HEALTH_BAR disabled, but we need still a string for some reason.
*/
std::string durability_indicator( bool include_intact = false ) const;

/** If possible to repair this item what tools could potentially be used for this purpose? */
const std::set<itype_id> &repaired_with() const;

Expand Down
29 changes: 21 additions & 8 deletions src/iuse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1674,9 +1674,11 @@ int iuse::sew_advanced( player *p, item *it, bool, const tripoint & )
rn -= mod_count * 10; // Other mods

if( rn <= 8 ) {
const std::string startdurability = mod.durability_indicator( true );
const auto destroyed = mod.inc_damage();
p->add_msg_if_player( m_bad, _( "You damage your %s trying to modify it!" ),
mod.tname() );
const std::string resultdurability = mod.durability_indicator( true );
p->add_msg_if_player( m_bad, _( "You damage your %s trying to modify it! ( %s-> %s)" ),
mod.tname( 1, false ), startdurability, resultdurability );
if( destroyed ) {
p->add_msg_if_player( m_bad, _( "You destroy it!" ) );
p->i_rem_keep_contents( pos );
Expand Down Expand Up @@ -5436,27 +5438,32 @@ int iuse::gun_repair( player *p, item *it, bool, const tripoint & )
return 0;
}
/** @EFFECT_MECHANICS >=8 allows accurizing ranged weapons */
const std::string startdurability = fix.durability_indicator( true );
std::string resultdurability;
if( fix.damage() <= 0 ) {
sounds::sound( p->pos(), 6, sounds::sound_t::activity, "crunch" );
p->moves -= 2000 * p->fine_detail_vision_mod();
p->practice( skill_mechanics, 10 );
fix.mod_damage( -itype::damage_scale );
p->add_msg_if_player( m_good, _( "You accurize your %s." ), fix.tname() );
p->add_msg_if_player( m_good, _( "You accurize your %s." ), fix.tname( 1, false ) );

} else if( fix.damage() > itype::damage_scale ) {
sounds::sound( p->pos(), 8, sounds::sound_t::activity, "crunch" );
p->moves -= 1000 * p->fine_detail_vision_mod();
p->practice( skill_mechanics, 10 );
fix.mod_damage( -itype::damage_scale );
p->add_msg_if_player( m_good, _( "You repair your %s!" ), fix.tname() );
resultdurability = fix.durability_indicator( true );
p->add_msg_if_player( m_good, _( "You repair your %s! ( %s-> %s)" ), fix.tname( 1, false ),
startdurability, resultdurability );

} else {
sounds::sound( p->pos(), 8, sounds::sound_t::activity, "crunch" );
p->moves -= 500 * p->fine_detail_vision_mod();
p->practice( skill_mechanics, 10 );
fix.set_damage( 0 );
p->add_msg_if_player( m_good, _( "You repair your %s completely!" ),
fix.tname() );
resultdurability = fix.durability_indicator( true );
p->add_msg_if_player( m_good, _( "You repair your %s completely! ( %s-> %s)" ),
fix.tname( 1, false ), startdurability, resultdurability );
}
return it->type->charges_to_use();
}
Expand Down Expand Up @@ -5569,6 +5576,8 @@ int iuse::misc_repair( player *p, item *it, bool, const tripoint & )
fix.tname() );
return 0;
}
const std::string startdurability = fix.durability_indicator( true );
std::string resultdurability;
if( fix.damage() <= 0 ) {
p->moves -= 1000 * p->fine_detail_vision_mod();
p->practice( skill_fabrication, 10 );
Expand All @@ -5579,13 +5588,17 @@ int iuse::misc_repair( player *p, item *it, bool, const tripoint & )
p->moves -= 500 * p->fine_detail_vision_mod();
p->practice( skill_fabrication, 10 );
fix.mod_damage( -itype::damage_scale );
p->add_msg_if_player( m_good, _( "You repair your %s!" ), fix.tname() );
resultdurability = fix.durability_indicator( true );
p->add_msg_if_player( m_good, _( "You repair your %s! ( %s-> %s)" ), fix.tname( 1, false ),
startdurability, resultdurability );

} else {
p->moves -= 250 * p->fine_detail_vision_mod();
p->practice( skill_fabrication, 10 );
fix.set_damage( 0 );
p->add_msg_if_player( m_good, _( "You repair your %s completely!" ), fix.tname() );
resultdurability = fix.durability_indicator( true );
p->add_msg_if_player( m_good, _( "You repair your %s completely! ( %s-> %s)" ),
fix.tname( 1, false ), startdurability, resultdurability );
}
return it->type->charges_to_use();
}
Expand Down
13 changes: 10 additions & 3 deletions src/iuse_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2835,8 +2835,11 @@ repair_item_actor::repair_type repair_item_actor::default_action( const item &fi

bool damage_item( player &pl, item_location &fix )
{
const std::string startdurability = fix->durability_indicator( true );
const auto destroyed = fix->inc_damage();
pl.add_msg_if_player( m_bad, _( "You damage your %s!" ), fix->tname() );
const std::string resultdurability = fix->durability_indicator( true );
pl.add_msg_if_player( m_bad, _( "You damage your %s! ( %s-> %s)" ), fix->tname( 1, false ),
startdurability, resultdurability );
if( destroyed ) {
pl.add_msg_if_player( m_bad, _( "You destroy it!" ) );
if( fix.where() == item_location::type::character ) {
Expand Down Expand Up @@ -2902,13 +2905,17 @@ repair_item_actor::attempt_hint repair_item_actor::repair( player &pl, item &too

if( action == RT_REPAIR ) {
if( roll == SUCCESS ) {
const std::string startdurability = fix->durability_indicator( true );
const auto damage = fix->damage();
handle_components( pl, *fix, false, false );
fix->set_damage( std::max( damage - itype::damage_scale, 0 ) );
const std::string resultdurability = fix->durability_indicator( true );
if( damage > itype::damage_scale ) {
pl.add_msg_if_player( m_good, _( "You repair your %s!" ), fix->tname() );
pl.add_msg_if_player( m_good, _( "You repair your %s! ( %s-> %s)" ), fix->tname( 1, false ),
startdurability, resultdurability );
} else {
pl.add_msg_if_player( m_good, _( "You repair your %s completely!" ), fix->tname() );
pl.add_msg_if_player( m_good, _( "You repair your %s completely! ( %s-> %s)" ), fix->tname( 1,
false ), startdurability, resultdurability );
}
return AS_SUCCESS;
}
Expand Down
11 changes: 6 additions & 5 deletions src/veh_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ bool repair_part( vehicle &veh, vehicle_part &pt, Character &who_c )
}

// If part is broken, it will be destroyed and references invalidated
std::string partname;
std::string partname = pt.name( false );
const std::string startdurability = "<color_" + string_from_color( pt.get_base().damage_color() ) +
">" + pt.get_base(). damage_symbol() + " </color>";
bool wasbroken = pt.is_broken();
if( wasbroken ) {
const int dir = pt.direction;
Expand All @@ -161,16 +163,15 @@ bool repair_part( vehicle &veh, vehicle_part &pt, Character &who_c )
const int partnum = veh.install_part( loc, replacement_id, std::move( base ) );
veh.parts[partnum].direction = dir;
veh.part_removal_cleanup();
partname = veh.parts[partnum].name();
} else {
veh.set_hp( pt, pt.info().durability );
partname = pt.name();
}

// TODO: NPC doing that
who.add_msg_if_player( m_good,
wasbroken ? _( "You replace the %1$s's %2$s." ) : _( "You repair the %1$s's %2$s." ), veh.name,
partname );
wasbroken ? _( "You replace the %1$s's %2$s. (was %3$s)" ) :
_( "You repair the %1$s's %2$s. (was %3$s)" ), veh.name,
partname, startdurability );
return true;
}

Expand Down
7 changes: 5 additions & 2 deletions src/vehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,11 @@ struct vehicle_part {
return flags &= ~flag;
}

/** Translated name of a part inclusive of any current status effects */
std::string name() const;
/**
* Translated name of a part inclusive of any current status effects
* with_prefix as true indicates the durability symbol should be prepended
*/
std::string name( bool with_prefix = true ) const;

static constexpr int name_offset = 7;
/** Stack of the containing vehicle's name, when it it stored as part of another vehicle */
Expand Down
8 changes: 5 additions & 3 deletions src/vehicle_part.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ item vehicle_part::properties_to_item() const
return tmp;
}

std::string vehicle_part::name() const
std::string vehicle_part::name( bool with_prefix ) const
{
auto res = info().name();

Expand All @@ -97,8 +97,10 @@ std::string vehicle_part::name() const
res += string_format( _( " holding %s" ), base.get_var( "contained_name" ) );
}

res.insert( 0, "<color_" + string_from_color( this->base.damage_color() ) + ">" +
this->base.damage_symbol() + "</color> " );
if( with_prefix ) {
res.insert( 0, "<color_" + string_from_color( this->base.damage_color() ) + ">" +
this->base.damage_symbol() + "</color> " );
}
return res;
}

Expand Down