Skip to content

Commit

Permalink
fix: electrosense CBM's voltmeter can be used in advanced deconstruct…
Browse files Browse the repository at this point in the history
…ion (#5744)
  • Loading branch information
chaosvolt authored Nov 20, 2024
1 parent d71ccd3 commit dd898d0
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 2 deletions.
1 change: 1 addition & 0 deletions data/json/bionics.json
Original file line number Diff line number Diff line change
Expand Up @@ -1301,6 +1301,7 @@
"name": { "str": "Electrosense Voltmeter" },
"description": "Using this bionic allows you to check the status of any local grid connections or battery charge in your surroundings, as well as make modifications to grid connections.",
"act_cost": "10 J",
"fake_item": "voltmeter_bionic",
"included": true
},
{
Expand Down
10 changes: 10 additions & 0 deletions data/json/items/fake.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@
[ "BUTCHER", -38 ]
]
},
{
"id": "voltmeter_bionic",
"sub": "voltmeter",
"copy-from": "fake_item",
"type": "TOOL",
"name": { "str": "integrated voltmeter" },
"flags": [ "TRADER_AVOID", "USES_BIONIC_POWER" ],
"max_charges": 10000,
"use_action": [ "REPORT_GRID_CHARGE", "REPORT_GRID_CONNECTIONS", "MODIFY_GRID_CONNECTIONS" ]
},
{
"id": "fake_goggles",
"copy-from": "fake_item",
Expand Down
2 changes: 1 addition & 1 deletion src/bionics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,7 @@ bool Character::activate_bionic( bionic &bio, bool eff_only, bool *close_bionics
} else if( bio.id == bio_electrosense_voltmeter ) {
add_msg_activate();
item *vtm;
vtm = item::spawn_temporary( "voltmeter", calendar::start_of_cataclysm );
vtm = item::spawn_temporary( "voltmeter_bionic", calendar::start_of_cataclysm );
invoke_item( vtm );
} else {
add_msg_activate();
Expand Down
5 changes: 5 additions & 0 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ static const itype_id itype_rope_6( "rope_6" );
static const itype_id itype_snare_trigger( "snare_trigger" );
static const itype_id itype_string_36( "string_36" );
static const itype_id itype_toolset( "toolset" );
static const itype_id itype_voltmeter_bionic( "voltmeter_bionic" );
static const itype_id itype_UPS( "UPS" );
static const itype_id itype_UPS_off( "UPS_off" );
static const itype_id itype_power_storage( "bio_power_storage" );
Expand Down Expand Up @@ -10046,6 +10047,10 @@ std::vector<detached_ptr<item>> Character::use_charges( const itype_id &what, in
if( qty <= 0 ) {
return res;

} else if( what == itype_voltmeter_bionic ) {
mod_power_level( units::from_kilojoule( -qty ) );
return res;

} else if( what == itype_toolset ) {
mod_power_level( units::from_kilojoule( -qty ) );
return res;
Expand Down
3 changes: 2 additions & 1 deletion src/crafting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ static const trait_id trait_BURROW( "BURROW" );
static const trait_id trait_DEBUG_HS( "DEBUG_HS" );
static const trait_id trait_HYPEROPIC( "HYPEROPIC" );

static const flag_id flag_BIONIC_TOGGLED( "BIONIC_TOGGLED" );
static const std::string flag_BLIND_EASY( "BLIND_EASY" );
static const std::string flag_BLIND_HARD( "BLIND_HARD" );
static const std::string flag_FULL_MAGAZINE( "FULL_MAGAZINE" );
Expand Down Expand Up @@ -562,7 +563,7 @@ const inventory &Character::crafting_inventory( const tripoint &src_pos, int rad
cached_crafting_inventory += worn;
for( const bionic &bio : *my_bionics ) {
const bionic_data &bio_data = bio.info();
if( ( !bio_data.activated || bio.powered ) &&
if( ( !bio_data.has_flag( flag_BIONIC_TOGGLED ) || bio.powered ) &&
!bio_data.fake_item.is_empty() ) {
cached_crafting_inventory += *item::spawn_temporary( bio.info().fake_item,
calendar::turn, units::to_kilojoule( get_power_level() ) );
Expand Down
14 changes: 14 additions & 0 deletions src/visitable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@
static const itype_id itype_apparatus( "apparatus" );
static const itype_id itype_adv_UPS_off( "adv_UPS_off" );
static const itype_id itype_toolset( "toolset" );
static const itype_id itype_voltmeter_bionic( "voltmeter_bionic" );
static const itype_id itype_UPS( "UPS" );
static const itype_id itype_UPS_off( "UPS_off" );
static const itype_id itype_bio_armor( "bio_armor" );

static const quality_id qual_BUTCHER( "BUTCHER" );

static const bionic_id bio_tools( "bio_tools" );
static const bionic_id bio_electrosense_voltmeter( "bio_electrosense_voltmeter" );
static const bionic_id bio_ups( "bio_ups" );

static const flag_id flag_BIONIC_ARMOR_INTERFACE( "BIONIC_ARMOR_INTERFACE" );
Expand Down Expand Up @@ -1054,6 +1056,14 @@ int visitable<Character>::charges_of( const itype_id &what, int limit,
}
}

if( what == itype_voltmeter_bionic ) {
if( p && p->has_bionic( bio_electrosense_voltmeter ) ) {
return std::min( units::to_kilojoule( p->get_power_level() ), limit );
} else {
return 0;
}
}

if( what == itype_bio_armor ) {
float efficiency = 1;
int power_charges = 0;
Expand Down Expand Up @@ -1167,6 +1177,10 @@ int visitable<Character>::amount_of( const itype_id &what, bool pseudo, int limi
return 1;
}

if( what == itype_voltmeter_bionic && pseudo && self->has_bionic( bio_electrosense_voltmeter ) ) {
return 1;
}

if( what == itype_apparatus && pseudo ) {
int qty = 0;
visit_items( [&qty, &limit, &filter]( const item * e ) {
Expand Down

0 comments on commit dd898d0

Please sign in to comment.