From c120c3472774d322ee8db4af82201e8d0ef54e85 Mon Sep 17 00:00:00 2001 From: Alexey Kim Date: Thu, 6 Oct 2022 23:09:34 +0300 Subject: [PATCH] Translate weakpoint name --- src/creature.cpp | 2 +- src/weakpoint.cpp | 9 +++++++-- src/weakpoint.h | 5 ++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/creature.cpp b/src/creature.cpp index d6f057430894e..956464f2efd5a 100644 --- a/src/creature.cpp +++ b/src/creature.cpp @@ -1152,7 +1152,7 @@ dealt_damage_instance Creature::deal_damage( Creature *source, bodypart_id bp, dealt_damage_instance dealt_dams; const weakpoint *wp = absorb_hit( attack_copy, bp, d ); - dealt_dams.wp_hit = wp == nullptr ? "" : wp->name; + dealt_dams.wp_hit = wp == nullptr ? "" : wp->get_name(); // Add up all the damage units dealt for( const damage_unit &it : d.damage_units ) { diff --git a/src/weakpoint.cpp b/src/weakpoint.cpp index ef9a9b21cbf3e..da8de5d07e2c1 100644 --- a/src/weakpoint.cpp +++ b/src/weakpoint.cpp @@ -433,10 +433,15 @@ void weakpoint::load( const JsonObject &jo ) // Set the ID to the name, if not provided. if( !jo.has_string( "id" ) ) { - id = name; + assign( jo, "name", id ); } } +std::string weakpoint::get_name() const +{ + return name.translated(); +} + void weakpoint::apply_to( resistances &resistances ) const { for( int i = 0; i < static_cast( damage_type::NUM ); ++i ) { @@ -512,7 +517,7 @@ const weakpoint *weakpoints::select_weakpoint( const weakpoint_attack &attack ) float hit_chance = new_reweighed - reweighed; add_msg_debug( debugmode::DF_MONSTER, "Weakpoint Selection: weakpoint %s, hit_chance %.4f", - weakpoint.name, hit_chance ); + weakpoint.get_name(), hit_chance ); if( idx < hit_chance ) { return &weakpoint; } diff --git a/src/weakpoint.h b/src/weakpoint.h index 36139fa73433f..93cc7d1087315 100644 --- a/src/weakpoint.h +++ b/src/weakpoint.h @@ -10,6 +10,7 @@ #include "damage.h" #include "optional.h" +#include "translation.h" #include "type_id.h" class Character; @@ -117,7 +118,7 @@ struct weakpoint { // ID of the weakpoint. Equal to the name, if not provided. std::string id; // Name of the weakpoint. Can be empty. - std::string name; + translation name; // Percent chance of hitting the weakpoint. Can be increased by skill. float coverage = 100.0f; // Multiplier for existing armor values. Defaults to 1. @@ -138,6 +139,8 @@ struct weakpoint { weakpoint_difficulty difficulty; weakpoint(); + // Gets translated name + std::string get_name() const; // Apply the armor multipliers and offsets to a set of resistances. void apply_to( resistances &resistances ) const; // Apply the damage multipliers to a set of damage values.