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

Bionics can require another bionic #66996

Merged
Merged
Show file tree
Hide file tree
Changes from 13 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
3 changes: 2 additions & 1 deletion data/json/bionics.json
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,8 @@
"flags": [ "BIONIC_TOGGLED", "BIONIC_NPC_USABLE" ],
"act_cost": "10 kJ",
"react_cost": "10 kJ",
"time": "1 s"
"time": "1 s",
"required_bionic": "bio_weight"
},
{
"id": "bio_infrared",
Expand Down
21 changes: 21 additions & 0 deletions src/bionics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ void bionic_data::load( const JsonObject &jsobj, const std::string &src )
optional( jsobj, was_loaded, "included_bionics", included_bionics );
optional( jsobj, was_loaded, "included", included );
optional( jsobj, was_loaded, "upgraded_bionic", upgraded_bionic );
optional( jsobj, was_loaded, "required_bionic", required_bionic );
optional( jsobj, was_loaded, "fuel_options", fuel_opts );
optional( jsobj, was_loaded, "activated_on_install", activated_on_install, false );

Expand Down Expand Up @@ -568,6 +569,14 @@ void bionic_data::check_bionic_consistency()
bio.id.c_str(), bio.upgraded_bionic.c_str() );
}
}
if( bio.required_bionic ) {
if( bio.required_bionic == bio.id ) {
debugmsg( "Bionic %s requires itself as a prerequisite for installation", bio.id.c_str() );
} else if( !bio.required_bionic.is_valid() ) {
debugmsg( "Bionic %s requires undefined bionic %s",
bio.id.c_str(), bio.required_bionic.c_str() );
}
}
if( !item::type_is_defined( bio.itype() ) && !bio.included ) {
debugmsg( "Bionic %s has no defined item version", bio.id.c_str() );
}
Expand Down Expand Up @@ -2113,6 +2122,14 @@ bool Character::can_uninstall_bionic( const bionic &bio, Character &installer, b
return false;
}

for( const bionic_id &bid : get_bionics() ) {
if( bid->required_bionic && bid->required_bionic == bio.id ) {
popup( _( "%s cannot be removed because installed bionic %s requires it." ), bio.id->name,
bid->name );
return false;
anoobindisguise marked this conversation as resolved.
Show resolved Hide resolved
}
}

if( bio.id->cant_remove_reason.has_value() ) {
popup( string_format( bio.id->cant_remove_reason.value(), disp_name( true ), disp_name() ) );
return false;
Expand Down Expand Up @@ -2331,6 +2348,10 @@ ret_val<void> Character::is_installable( const item *it, const bool by_autodoc )
!has_bionic( bid->upgraded_bionic ) &&
it->is_upgrade() ) {
return ret_val<void>::make_failure( _( "No base version installed." ) );
} else if( bid->required_bionic &&
!has_bionic( bid->required_bionic ) ) {
return ret_val<void>::make_failure( _( "CBM requires prior installation of %s." ),
bid->required_bionic.obj().name );
} else if( std::any_of( bid->available_upgrades.begin(),
bid->available_upgrades.end(),
[this]( const bionic_id & b ) {
Expand Down
8 changes: 7 additions & 1 deletion src/bionics.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,13 @@ struct bionic_data {
*/
std::set<bionic_id> available_upgrades;

/**Requirement to bionic installation*/
/**
* Id of another bionic which this bionic needs to have installed to be installed.
* Also prevents that bionic from being removed while this bionic is installed.
*/
bionic_id required_bionic;

/**Requirement to bionic installation - this is a crafting requirement such as soldering_standard or surface_heat*/
requirement_id installation_requirement;

cata::flat_set<json_character_flag> flags;
Expand Down
6 changes: 6 additions & 0 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5112,6 +5112,12 @@ void item::bionic_info( std::vector<iteminfo> &info, const iteminfo_query *parts

insert_separation_line( info );

if( bid->required_bionic ) {
info.emplace_back( "CBM", string_format( "* This CBM requires another CBM to also be installed: %s",
bid->required_bionic->name ) );
}
insert_separation_line( info );

// TODO refactor these almost identical blocks
if( !bid->encumbrance.empty() ) {
info.emplace_back( "DESCRIPTION", _( "<bold>Encumbrance</bold>:" ),
Expand Down