Skip to content

Commit

Permalink
Use new translated weapon category ids from #52639
Browse files Browse the repository at this point in the history
  • Loading branch information
dseguin committed Nov 14, 2021
1 parent 3958a97 commit b0741a4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
5 changes: 5 additions & 0 deletions data/mods/TEST_DATA/weapons.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
[
{
"type": "weapon_category",
"id": "TEST_CAT1",
"name": "Test Category"
},
{
"type": "GENERIC",
"id": "test_weapon1",
Expand Down
14 changes: 11 additions & 3 deletions src/martialarts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ void ma_requirements::load( const JsonObject &jo, const std::string & )
optional( jo, was_loaded, "melee_allowed", melee_allowed, false );
optional( jo, was_loaded, "unarmed_weapons_allowed", unarmed_weapons_allowed, true );
if( jo.has_string( "weapon_categories_allowed" ) ) {
weapon_categories_allowed.emplace_back( jo.get_string( "weapon_categories_allowed" ) );
weapon_category_id tmp_id;
mandatory( jo, was_loaded, "weapon_categories_allowed", tmp_id );
weapon_categories_allowed.emplace_back( tmp_id );
} else {
optional( jo, was_loaded, "weapon_categories_allowed", weapon_categories_allowed );
}
Expand Down Expand Up @@ -561,7 +563,7 @@ bool ma_requirements::is_valid_character( const Character &u ) const

if( !weapon_categories_allowed.empty() ) {
bool valid_weap_cat = false;
for( const std::string &w_cat : weapon_categories_allowed ) {
for( const weapon_category_id &w_cat : weapon_categories_allowed ) {
if( u.used_weapon().typeId()->weapon_category.count( w_cat ) > 0 ) {
valid_weap_cat = true;
}
Expand Down Expand Up @@ -628,7 +630,13 @@ std::string ma_requirements::get_description( bool buff ) const
if( !weapon_categories_allowed.empty() ) {
dump += n_gettext( "<bold>Weapon category required: </bold>",
"<bold>Weapon categories required: </bold>", weapon_categories_allowed.size() );
dump += enumerate_as_string( weapon_categories_allowed ) + "\n";
dump += enumerate_as_string( weapon_categories_allowed.begin(),
weapon_categories_allowed.end(), []( const weapon_category_id & w_cat ) {
if( !w_cat.is_valid() ) {
return w_cat.str();
}
return w_cat->name().translated();
} ) + "\n";
}

if( !req_buffs_all.empty() ) {
Expand Down
2 changes: 1 addition & 1 deletion src/martialarts.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ struct ma_requirements {
bool wall_adjacent; // Does it only work near a wall?

/** Weapon categories compatible with this requirement. If empty, allow any weapon category. */
std::vector<std::string> weapon_categories_allowed;
std::vector<weapon_category_id> weapon_categories_allowed;

/** Minimum amount of given skill to trigger this bonus */
std::vector<std::pair<skill_id, int>> min_skill;
Expand Down

0 comments on commit b0741a4

Please sign in to comment.