From 3e27a158bd7890937d6a33e16306690551d14355 Mon Sep 17 00:00:00 2001 From: Alexey Kim Date: Fri, 7 Oct 2022 00:11:27 +0300 Subject: [PATCH 1/2] Translate weakpoint name --- src/creature.cpp | 2 +- src/weakpoint.cpp | 9 +++++++-- src/weakpoint.h | 5 ++++- tests/weakpoint_test.cpp | 12 ++++++------ 4 files changed, 18 insertions(+), 10 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..444f7556f44a3 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.id, 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. diff --git a/tests/weakpoint_test.cpp b/tests/weakpoint_test.cpp index ac4668b5f3952..db80d0e10748c 100644 --- a/tests/weakpoint_test.cpp +++ b/tests/weakpoint_test.cpp @@ -143,19 +143,19 @@ TEST_CASE( "Check order of weakpoint set application", "[monster][weakpoint]" ) for( const weakpoint &wp : mon_test_zombie_cop->weakpoints.weakpoint_list ) { if( wp.id == "test_head" ) { has_wp_head = true; - CHECK( wp.name == "inline head" ); + CHECK( wp.get_name() == "inline head" ); } else if( wp.id == "test_eye" ) { has_wp_eye = true; - CHECK( wp.name == "humanoid eye" ); + CHECK( wp.get_name() == "humanoid eye" ); } else if( wp.id == "test_neck" ) { has_wp_neck = true; - CHECK( wp.name == "special neck" ); + CHECK( wp.get_name() == "special neck" ); } else if( wp.id == "test_arm" ) { has_wp_arm = true; - CHECK( wp.name == "inline arm" ); + CHECK( wp.get_name() == "inline arm" ); } else if( wp.id == "test_leg" ) { has_wp_leg = true; - CHECK( wp.name == "inline leg" ); + CHECK( wp.get_name() == "inline leg" ); } } REQUIRE( has_wp_head ); @@ -259,4 +259,4 @@ TEST_CASE( "Check copy-from inheritance between sets and inline weakpoints", for( const auto &found : wp_found ) { CHECK( found.second.first == true ); } -} \ No newline at end of file +} From ee1d118bac2f662fe09c4194cad1589f17554f1c Mon Sep 17 00:00:00 2001 From: Alexey Kim Date: Fri, 7 Oct 2022 00:11:36 +0300 Subject: [PATCH 2/2] Translate weakpoint effect message --- src/weakpoint.cpp | 9 +++++++-- src/weakpoint.h | 4 +++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/weakpoint.cpp b/src/weakpoint.cpp index 444f7556f44a3..61a4555438469 100644 --- a/src/weakpoint.cpp +++ b/src/weakpoint.cpp @@ -256,6 +256,11 @@ weakpoint_effect::weakpoint_effect() : intensity( 0, 0 ), damage_required( 0.0f, 100.0f ) {} +std::string weakpoint_effect::get_message() const +{ + return message.translated(); +} + void weakpoint_effect::apply_to( Creature &target, int total_damage, const weakpoint_attack &attack ) const { @@ -273,8 +278,8 @@ void weakpoint_effect::apply_to( Creature &target, int total_damage, time_duration::from_turns( rng( duration.first, duration.second ) ), permanent, rng( intensity.first, intensity.second ) ); - if( !message.empty() && attack.source != nullptr && attack.source->is_avatar() ) { - add_msg_if_player_sees( target, m_good, message, target.get_name() ); + if( !get_message().empty() && attack.source != nullptr && attack.source->is_avatar() ) { + add_msg_if_player_sees( target, m_good, get_message(), target.get_name() ); } } diff --git a/src/weakpoint.h b/src/weakpoint.h index 93cc7d1087315..c792fb026a163 100644 --- a/src/weakpoint.h +++ b/src/weakpoint.h @@ -68,9 +68,11 @@ struct weakpoint_effect { // The range of damage, as a percentage of max health, required to the effect. std::pair damage_required; // The message to print, if the player causes the effect. - std::string message; + translation message; weakpoint_effect(); + // Gets translated effect message + std::string get_message() const; // Maybe apply an effect to the target. void apply_to( Creature &target, int total_damage, const weakpoint_attack &attack ) const; void load( const JsonObject &jo );