Skip to content

Commit

Permalink
Translate weakpoint name
Browse files Browse the repository at this point in the history
  • Loading branch information
irwiss committed Oct 6, 2022
1 parent 138556e commit 3e27a15
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
9 changes: 7 additions & 2 deletions src/weakpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>( damage_type::NUM ); ++i ) {
Expand Down Expand Up @@ -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;
}
Expand Down
5 changes: 4 additions & 1 deletion src/weakpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "damage.h"
#include "optional.h"
#include "translation.h"
#include "type_id.h"

class Character;
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down
12 changes: 6 additions & 6 deletions tests/weakpoint_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
}
}
}

0 comments on commit 3e27a15

Please sign in to comment.