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

Jsonize crafting skill penalty from mutations #36565

Merged
merged 4 commits into from
Dec 31, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
12 changes: 12 additions & 0 deletions data/json/mutations/mutations.json
Original file line number Diff line number Diff line change
Expand Up @@ -4853,6 +4853,7 @@
"description": "Your hands have fused into quasi-paws. Fine manipulation is a challenge: permanent hand encumbrance of 10, difficulty with delicate craftwork, and your gloves don't fit. But they handle water better.",
"encumbrance_always": [ [ "HAND_L", 10 ], [ "HAND_R", 10 ] ],
"restricts_gear": [ "HAND_L", "HAND_R" ],
"craft_skill_bonus": [ [ "electronics", -2 ], [ "tailor", -2 ], [ "mechanics", -2 ] ],
"types": [ "HANDS" ],
"prereqs": [ "CLAWS", "CLAWS_RETRACT", "CLAWS_RAT" ],
"cancels": [ "TALONS" ],
Expand All @@ -4868,6 +4869,17 @@
"ugliness": 3,
"mixed_effect": true,
"description": "Your paws are much larger now. Manual dexterity is difficult: permanent hand encumbrance of 20, serious problems crafting, and no gloves. But you can swim more effectively.",
"craft_skill_bonus": [
[ "electronics", -4 ],
[ "tailor", -4 ],
[ "mechanics", -4 ],
[ "firstaid", -2 ],
[ "computer", -2 ],
[ "traps", -2 ],
[ "fabrication", -2 ],
[ "cooking", -2 ],
[ "survival", -2 ]
],
"encumbrance_always": [ [ "HAND_L", 20 ], [ "HAND_R", 20 ] ],
"restricts_gear": [ "HAND_L", "HAND_R" ],
"types": [ "HANDS" ],
Expand Down
1 change: 1 addition & 0 deletions doc/JSON_INFO.md
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,7 @@ Note that even though most statistics yield an integer, you should still use
"good": 1 } ] // "neutral/good/ignored" // Good increases pos and cancels neg, neut cancels neg, ignored cancels both
"vitamin_rates": [ [ "vitC", -1200 ] ], // How much extra vitamins do you consume per minute. Negative values mean production
"vitamins_absorb_multi": [ [ "flesh", [ [ "vitA", 0 ], [ "vitB", 0 ], [ "vitC", 0 ], [ "calcium", 0 ], [ "iron", 0 ] ], [ "all", [ [ "vitA", 2 ], [ "vitB", 2 ], [ "vitC", 2 ], [ "calcium", 2 ], [ "iron", 2 ] ] ] ], // multiplier of vitamin absorption based on material. "all" is every material. supports multiple materials.
"craft_skill_bonus": [ [ "electronics", -2 ], [ "tailor", -2 ], [ "mechanics", -2 ] ], // Skill affected by the mutation and their bonuses. Bonuses can be negative, a bonus of 4 is worth 1 full skill level.
"restricts_gear" : [ "TORSO" ], //list of bodyparts that get restricted by this mutation
"allow_soft_gear" : true, //If there is a list of 'restricts_gear' this sets if the location still allows items made out of soft materials (Only one of the types need to be soft for it to be considered soft). (default: false)
"destroys_gear" : true, //If true, destroys the gear in the 'restricts_gear' location when mutated into. (default: false)
Expand Down
18 changes: 6 additions & 12 deletions src/crafting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "map.h"
#include "map_iterator.h"
#include "messages.h"
#include "mutation.h"
#include "npc.h"
#include "options.h"
#include "output.h"
Expand Down Expand Up @@ -73,8 +74,6 @@ static const efftype_id effect_contacts( "contacts" );
void drop_or_handle( const item &newit, player &p );

static const trait_id trait_DEBUG_HS( "DEBUG_HS" );
static const trait_id trait_PAWS_LARGE( "PAWS_LARGE" );
static const trait_id trait_PAWS( "PAWS" );
static const trait_id trait_BURROW( "BURROW" );

static bool crafting_allowed( const player &p, const recipe &rec )
Expand Down Expand Up @@ -923,17 +922,12 @@ double player::crafting_success_roll( const recipe &making ) const

// It's tough to craft with paws. Fortunately it's just a matter of grip and fine-motor,
// not inability to see what you're doing
if( has_trait( trait_PAWS ) || has_trait( trait_PAWS_LARGE ) ) {
int paws_rank_penalty = 0;
if( has_trait( trait_PAWS_LARGE ) ) {
paws_rank_penalty += 1;
}
if( making.skill_used == skill_id( "electronics" )
|| making.skill_used == skill_id( "tailor" )
|| making.skill_used == skill_id( "mechanics" ) ) {
paws_rank_penalty += 1;
for( const std::pair< trait_id, trait_data > &mut : my_mutations ) {
for( const std::pair<skill_id, int> &skib : mut.first->craft_skill_bonus ) {
if( making.skill_used == skib.first ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

craft_skill_bonus is a std::map. You can lookup keys in a map, there is a function for that. You do not need to iterate over all entries of the map.

skill_dice += skib.second;
}
}
skill_dice -= paws_rank_penalty * 4;
}

// Sides on dice is 16 plus your current intelligence
Expand Down
3 changes: 3 additions & 0 deletions src/mutation.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ struct mutation_branch {
cata::optional<int> scent_mask;
int bleed_resist = 0;

/**Map of crafting skills modifiers, can be negative*/
std::map<skill_id, int> craft_skill_bonus;

/**What do you smell like*/
cata::optional<scenttype_id> scent_typeid;

Expand Down
10 changes: 10 additions & 0 deletions src/mutation_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,16 @@ void mutation_branch::load( const JsonObject &jo, const std::string & )
spells_learned.emplace( sp, ja.next_int() );
}

for( JsonArray ja : jo.get_array( "craft_skill_bonus" ) ) {
const skill_id skid( ja.next_string() );
if( skid.is_valid() ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the skill definition is loaded after the mutation is loaded? This will report that skill id as invalid. Id checking should be done after everything has been loaded.

craft_skill_bonus.emplace( skid, ja.next_int() );
} else {
jo.throw_error( "invalid skill_id" );
}

Fris0uman marked this conversation as resolved.
Show resolved Hide resolved
}

for( JsonArray ja : jo.get_array( "lumination" ) ) {
const body_part bp = get_body_part_token( ja.next_string() );
lumination.emplace( bp, ja.next_float() );
Expand Down