Skip to content

Commit

Permalink
Jsonize encumbrance from cbm (#32945)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fris0uman authored and ZhilkinSerg committed Aug 6, 2019
1 parent 67c4e98 commit aec03e9
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 21 deletions.
13 changes: 13 additions & 0 deletions data/json/bionics.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
"name": "Shotgun Arm",
"description": "Concealed in your left arm is a single shot 12 gauge shotgun. Activate the bionic to fire and reload the shotgun.",
"occupied_bodyparts": [ [ "ARM_L", 15 ] ],
"encumbrance": [ [ "ARM_L", 5 ] ],
"act_cost": 5,
"fake_item": "bio_shotgun_gun",
"flags": [ "BIONIC_TOGGLED", "BIONIC_WEAPON", "NO_UNWIELD" ]
Expand Down Expand Up @@ -670,6 +671,7 @@
"name": "Bionic Nostril",
"description": "You're really not sure how the CBM ended up in your nose, but no matter how it got there this badly misplaced bionic makes it difficult to breathe. Increases mouth encumbrance by one.",
"occupied_bodyparts": [ [ "HEAD", 2 ], [ "MOUTH", 1 ] ],
"encumbrance": [ [ "MOUTH", 10 ] ],
"flags": [ "BIONIC_FAULTY" ]
},
{
Expand Down Expand Up @@ -716,6 +718,7 @@
"name": "Bionic Visual Impairment",
"description": "Due to a badly misplaced dielectric stylette, you are now suffering from mild optic neuropathy. Increases eye encumbrance by one.",
"occupied_bodyparts": [ [ "EYES", 1 ] ],
"encumbrance": [ [ "EYES", 10 ] ],
"flags": [ "BIONIC_FAULTY" ]
},
{
Expand Down Expand Up @@ -941,6 +944,15 @@
"name": "Wire-Induced Stiffness",
"description": "Improperly installed wires cause a physical stiffness in most of your body, causing increased encumbrance.",
"occupied_bodyparts": [ [ "TORSO", 2 ], [ "ARM_L", 1 ], [ "ARM_R", 1 ], [ "LEG_L", 1 ], [ "LEG_R", 1 ], [ "FOOT_L", 1 ], [ "FOOT_R", 1 ] ],
"encumbrance": [
[ "TORSO", 10 ],
[ "ARM_L", 10 ],
[ "ARM_R", 10 ],
[ "LEG_L", 10 ],
[ "LEG_R", 10 ],
[ "FOOT_L", 10 ],
[ "FOOT_R", 10 ]
],
"flags": [ "BIONIC_FAULTY" ]
},
{
Expand Down Expand Up @@ -991,6 +1003,7 @@
"name": "Self-Locking Thumbs",
"description": "Self-locking thumbs hold tight (even when you really don't want them to) and don't let go (even when you'd rather they did). Increases hand encumbrance by two, while failing to improve your ability to hold objects whatsoever.",
"occupied_bodyparts": [ [ "HAND_L", 1 ], [ "HAND_R", 1 ] ],
"encumbrance": [ [ "HAND_L", 10 ], [ "HAND_R", 10 ] ],
"flags": [ "BIONIC_FAULTY" ]
},
{
Expand Down
2 changes: 2 additions & 0 deletions doc/JSON_INFO.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ Currently, only effect names, item action names, and item category names support
| cost | How many PUs it costs to use the bionic. (default: `0`)
| time | How long, when activated, between drawing cost. If 0, it draws power once. (default: `0`)
| description | In-game description.
| encumbrance | (_optional_) A list of body parts and how much this bionic encumber them.
| canceled_mutations | (_optional_) A list of mutations/traits that are removed when this bionic is installed (e.g. because it replaces the fault biological part).
| included_bionics | (_optional_) Additional bionics that are installed automatically when this bionic is installed. This can be used to install several bionics from one CBM item, which is useful as each of those can be activated independently.
| included | (_optional_) Whether this bionic is included with another. If true this bionic does not require a CBM item to be defined. (default: `false`)
Expand All @@ -186,6 +187,7 @@ Currently, only effect names, item action names, and item category names support
"faulty" : false,
"cost" : 0,
"time" : 0,
"encumbrance" : [ [ "TORSO", 10 ], [ "ARM_L", 10 ], [ "ARM_R", 10 ], [ "LEG_L", 10 ], [ "LEG_R", 10 ], [ "FOOT_L", 10 ], [ "FOOT_R", 10 ] ],
"description" : "You have a battery draining attachment, and thus can make use of the energy contained in normal, everyday batteries. Use 'E' to consume batteries.",
"canceled_mutations": ["HYPEROPIC"],
"included_bionics": ["bio_blindfold"]
Expand Down
9 changes: 9 additions & 0 deletions src/bionics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1985,6 +1985,15 @@ void load_bionic( JsonObject &jsobj )
jsobj.read( "included", new_bionic.included );
jsobj.read( "upgraded_bionic", new_bionic.upgraded_bionic );

JsonArray jsar = jsobj.get_array( "encumbrance" );
if( !jsar.empty() ) {
while( jsar.has_more() ) {
JsonArray ja = jsar.next_array();
new_bionic.encumbrance.emplace( get_body_part_token( ja.get_string( 0 ) ),
ja.get_int( 1 ) );
}
}

JsonArray jsarr = jsobj.get_array( "occupied_bodyparts" );
if( !jsarr.empty() ) {
while( jsarr.has_more() ) {
Expand Down
4 changes: 4 additions & 0 deletions src/bionics.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ struct bionic_data {
* Body part slots used to install this bionic, mapped to the amount of space required.
*/
std::map<body_part, size_t> occupied_bodyparts;
/**
* Body part encumbered by this bionic, mapped to the amount of encumbrance caused.
*/
std::map<body_part, int> encumbrance;
/**
* Fake item created for crafting with this bionic available.
* Also the item used for gun bionics.
Expand Down
25 changes: 4 additions & 21 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1899,30 +1899,13 @@ static void apply_mut_encumbrance( std::array<encumbrance_data, num_bp> &vals,

void Character::mut_cbm_encumb( std::array<encumbrance_data, num_bp> &vals ) const
{
if( has_bionic( bionic_id( "bio_stiff" ) ) ) {
// All but head, mouth and eyes
for( auto &val : vals ) {
val.encumbrance += 10;
}

vals[bp_head].encumbrance -= 10;
vals[bp_mouth].encumbrance -= 10;
vals[bp_eyes].encumbrance -= 10;
for( const bionic &bio : *my_bionics ) {
for( const auto &element : bio.info().encumbrance ) {
vals[element.first].encumbrance += element.second;
}
}

if( has_bionic( bionic_id( "bio_nostril" ) ) ) {
vals[bp_mouth].encumbrance += 10;
}
if( has_bionic( bionic_id( "bio_shotgun" ) ) ) {
vals[bp_arm_l].encumbrance += 5;
}
if( has_bionic( bionic_id( "bio_thumbs" ) ) ) {
vals[bp_hand_l].encumbrance += 10;
vals[bp_hand_r].encumbrance += 10;
}
if( has_bionic( bionic_id( "bio_pokedeye" ) ) ) {
vals[bp_eyes].encumbrance += 10;
}
if( has_active_bionic( bionic_id( "bio_shock_absorber" ) ) ) {
for( auto &val : vals ) {
val.encumbrance += 3; // Slight encumbrance to all parts except eyes
Expand Down

0 comments on commit aec03e9

Please sign in to comment.