Skip to content

Commit

Permalink
Jsonize environemental protection form CBMs (#32939)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fris0uman authored and ZhilkinSerg committed Aug 6, 2019
1 parent 0e26fde commit 67c4e98
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 11 deletions.
2 changes: 2 additions & 0 deletions data/json/bionics.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"name": "Protective Lenses",
"description": "Your eye sockets have been surgically sealed with highly protective mirrored lenses and your tear ducts have been re-routed to your mouth. When you cry, you must spit out or swallow your tears.",
"occupied_bodyparts": [ [ "EYES", 1 ] ],
"env_protec": [ [ "EYES", 7 ] ],
"flags": [ "BIONIC_NPC_USABLE", "BIONIC_SHOCKPROOF" ]
},
{
Expand Down Expand Up @@ -778,6 +779,7 @@
"name": "Air Filtration System",
"description": "Surgically implanted in your trachea is an advanced filtration system. If toxins, or airborne diseases find their way into your windpipe, the filter will attempt to remove them.",
"occupied_bodyparts": [ [ "TORSO", 4 ], [ "MOUTH", 2 ] ],
"env_protec": [ [ "MOUTH", 7 ] ],
"flags": [ "BIONIC_NPC_USABLE" ]
},
{
Expand Down
11 changes: 11 additions & 0 deletions doc/JSON_INFO.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ Currently, only effect names, item action names, and item category names support
| 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`)
| env_protec | (_optional_) How much environmental protection does this bionic provide on the specified body parts.
| occupied_bodyparts | (_optional_) A list of body parts occupied by this bionic, and the number of bionic slots it take on those parts.
```C++
{
Expand All @@ -187,6 +189,15 @@ Currently, only effect names, item action names, and item category names support
"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"]
},
{
"id": "bio_purifier",
"type": "bionic",
"name": "Air Filtration System",
"description": "Surgically implanted in your trachea is an advanced filtration system. If toxins, or airborne diseases find their way into your windpipe, the filter will attempt to remove them.",
"occupied_bodyparts": [ [ "TORSO", 4 ], [ "MOUTH", 2 ] ],
"env_protec": [ [ "MOUTH", 7 ] ],
"flags": [ "BIONIC_NPC_USABLE" ]
}
```

Expand Down
9 changes: 9 additions & 0 deletions src/bionics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1994,6 +1994,15 @@ void load_bionic( JsonObject &jsobj )
}
}

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

new_bionic.activated = new_bionic.toggled ||
new_bionic.power_activate > 0 ||
new_bionic.charge_time > 0;
Expand Down
2 changes: 2 additions & 0 deletions src/bionics.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ struct bionic_data {
* If true, this bionic is included with another.
*/
bool included = false;
/**Amount of environemental protection offered by this bionic*/
std::map<body_part, size_t> env_protec;
/**
* Body part slots used to install this bionic, mapped to the amount of space required.
*/
Expand Down
16 changes: 5 additions & 11 deletions src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ static const bionic_id bio_metabolics( "bio_metabolics" );
static const bionic_id bio_noise( "bio_noise" );
static const bionic_id bio_plut_filter( "bio_plut_filter" );
static const bionic_id bio_power_weakness( "bio_power_weakness" );
static const bionic_id bio_purifier( "bio_purifier" );
static const bionic_id bio_reactor( "bio_reactor" );
static const bionic_id bio_recycler( "bio_recycler" );
static const bionic_id bio_shakes( "bio_shakes" );
Expand Down Expand Up @@ -10186,19 +10185,14 @@ int player::get_env_resist( body_part bp ) const
}
}

if( bp == bp_mouth && has_bionic( bio_purifier ) && ret < 5 ) {
ret += 2;
if( ret > 5 ) {
ret = 5;
for( const bionic &bio : *my_bionics ) {
for( const auto &element : bio.info().env_protec ) {
if( element.first == bp || ( bp == bp_eyes && element.first == bp_head ) ) {
ret += element.second;
}
}
}

if( bp == bp_eyes && has_bionic( bio_armor_eyes ) && ret < 5 ) {
ret += 2;
if( ret > 5 ) {
ret = 5;
}
}
if( bp == bp_eyes && has_trait( trait_SEESLEEP ) ) {
ret += 8;
}
Expand Down

0 comments on commit 67c4e98

Please sign in to comment.