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

Allow installing and removing bionics through debug menu #2507

Merged
merged 2 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
20 changes: 0 additions & 20 deletions data/json/mutations/mutations.json
Original file line number Diff line number Diff line change
Expand Up @@ -6349,26 +6349,6 @@
"description": "Lets you instantly install torsion ratchets for your eight legs.",
"debug": true
},
{
"type": "mutation",
"id": "DEBUG_BIONIC_POWER",
"name": { "str": "Debug Bionic Power" },
"points": 99,
"valid": false,
"description": "For fueling your inner cybug. Activate to increase power capacity by 100 (can be repeated.)",
"debug": true,
"active": true
},
{
"type": "mutation",
"id": "DEBUG_BIONIC_POWERGEN",
"name": { "str": "Debug Bionic Powergen" },
"points": 99,
"valid": false,
"description": "Activate to increase power by an amount you specify (can be repeated).",
"debug": true,
"active": true
},
{
"type": "mutation",
"id": "SQUEAMISH",
Expand Down
5 changes: 0 additions & 5 deletions src/character_turn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ static const trait_id trait_CHITIN2( "CHITIN2" );
static const trait_id trait_CHITIN3( "CHITIN3" );
static const trait_id trait_COLDBLOOD4( "COLDBLOOD4" );
static const trait_id trait_COMPOUND_EYES( "COMPOUND_EYES" );
static const trait_id trait_DEBUG_BIONIC_POWER( "DEBUG_BIONIC_POWER" );
static const trait_id trait_EATHEALTH( "EATHEALTH" );
static const trait_id trait_FAT( "FAT" );
static const trait_id trait_FELINE_FUR( "FELINE_FUR" );
Expand Down Expand Up @@ -187,10 +186,6 @@ void Character::process_turn()
// Didn't just pick something up
last_item = itype_id( "null" );

if( !is_npc() && has_trait( trait_DEBUG_BIONIC_POWER ) ) {
mod_power_level( get_max_power_level() );
}

visit_items( [this]( item * e ) {
e->process_artifact( as_player(), pos() );
e->process_relic( *this );
Expand Down
6 changes: 5 additions & 1 deletion src/debug_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ void character_edit_menu( Character &c )
enum edit_character {
pick, desc, skills, stats, items, delete_items, item_worn,
hp, stamina, morale, pain, needs, healthy, status, mission_add, mission_edit,
tele, mutate, npc_class, attitude, opinion, effects,
tele, mutate, bionics, npc_class, attitude, opinion, effects,
learn_ma, unlock_recipes, learn_spells, level_spells
};

Expand All @@ -568,6 +568,7 @@ void character_edit_menu( Character &c )
uilist_entry( edit_character::healthy, true, 'a', _( "Set he[a]lth" ) ),
uilist_entry( edit_character::needs, true, 'n', _( "Set [n]eeds" ) ),
uilist_entry( edit_character::mutate, true, 'u', _( "M[u]tate" ) ),
uilist_entry( edit_character::bionics, true, 'b', _( "Edit [b]ionics" ) ),
uilist_entry( edit_character::status, true, '@', _( "Status Window [@]" ) ),
uilist_entry( edit_character::tele, true, 'e', _( "t[e]leport" ) ),
uilist_entry( edit_character::mission_edit, true, 'M', _( "Edit [M]issions (WARNING: Unstable!)" ) ),
Expand Down Expand Up @@ -916,6 +917,9 @@ void character_edit_menu( Character &c )
case edit_character::mutate:
wishmutate( &p );
break;
case edit_character::bionics:
wishbionics( *p.as_character() );
break;
case edit_character::healthy: {
uilist smenu;
smenu.addentry( 0, true, 'h', "%s: %d", _( "Health" ), p.get_healthy() );
Expand Down
1 change: 1 addition & 0 deletions src/debug_menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ void wishitem( player *p = nullptr );
void wishitem( player *p, const tripoint & );
void wishmonster( const cata::optional<tripoint> &p );
void wishmutate( player *p );
void wishbionics( Character &c );
void wishskill( player *p );
void mutation_wish();
void benchmark( int max_difference, bench_kind kind );
Expand Down
15 changes: 0 additions & 15 deletions src/mutation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ static const efftype_id effect_stunned( "stunned" );
static const trait_id trait_BURROW( "BURROW" );
static const trait_id trait_CARNIVORE( "CARNIVORE" );
static const trait_id trait_CHAOTIC_BAD( "CHAOTIC_BAD" );
static const trait_id trait_DEBUG_BIONIC_POWER( "DEBUG_BIONIC_POWER" );
static const trait_id trait_DEBUG_BIONIC_POWERGEN( "DEBUG_BIONIC_POWERGEN" );
static const trait_id trait_DEX_ALPHA( "DEX_ALPHA" );
static const trait_id trait_GLASSJAW( "GLASSJAW" );
static const trait_id trait_INT_ALPHA( "INT_ALPHA" );
Expand Down Expand Up @@ -580,19 +578,6 @@ void Character::activate_mutation( const trait_id &mut )
activity.values.push_back( to_turns<int>( startup_time ) );
return;
}
} else if( mut == trait_DEBUG_BIONIC_POWER ) {
mod_max_power_level( 100_kJ );
add_msg_if_player( m_good, _( "Bionic power storage increased by 100." ) );
tdata.powered = false;
return;
} else if( mut == trait_DEBUG_BIONIC_POWERGEN ) {
int npower;
if( query_int( npower, "Modify bionic power by how much? (Values are in joules)" ) ) {
mod_power_level( units::from_joule( npower ) );
add_msg_if_player( m_good, "Bionic power increased by %dJ.", npower );
tdata.powered = false;
}
return;
} else if( !mdata.spawn_item.is_empty() ) {
item tmpitem( mdata.spawn_item );
i_add_or_drop( tmpitem );
Expand Down
114 changes: 114 additions & 0 deletions src/wish.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <string>
#include <vector>

#include "bionics.h"
#include "calendar.h"
#include "catacharset.h"
#include "color.h"
Expand All @@ -35,7 +36,10 @@
#include "translations.h"
#include "type_id.h"
#include "ui.h"
#include "ui_manager.h"
#include "uistate.h"
#include "units.h"
#include "units_energy.h"

class wish_mutate_callback: public uilist_callback
{
Expand Down Expand Up @@ -315,6 +319,116 @@ void debug_menu::wishmutate( player *p )
} while( wmenu.ret >= 0 );
}

void debug_menu::wishbionics( Character &c )
{
std::vector<const itype *> cbm_items = item_controller->find( []( const itype & itm ) -> bool {
return itm.can_use( "install_bionic" );
} );
std::sort( cbm_items.begin(), cbm_items.end(), []( const itype * a, const itype * b ) {
return localized_compare( a->nname( 1 ), b->nname( 1 ) );
} );

while( true ) {
units::energy power_level = c.get_power_level();
units::energy power_max = c.get_max_power_level();
size_t num_installed = c.get_bionics().size();

bool can_uninstall = num_installed > 0;
bool can_uninstall_all = can_uninstall || power_max > 0_J;

uilist smenu;
smenu.text += string_format(
_( "Current power level: %s\nMax power: %s\nBionics installed: %d" ),
units::display( power_level ),
units::display( power_max ),
num_installed
);
smenu.addentry( 0, true, 'i', _( "Install from CBM…" ) );
smenu.addentry( 1, can_uninstall, 'u', _( "Uninstall…" ) );
smenu.addentry( 2, can_uninstall_all, 'U', _( "Uninstall all" ) );
smenu.addentry( 3, true, 'c', _( "Edit power capacity (kJ)" ) );
smenu.addentry( 4, true, 'C', _( "Edit power capacity (J)" ) );
smenu.addentry( 5, true, 'p', _( "Edit power level (kJ)" ) );
smenu.addentry( 6, true, 'P', _( "Edit power level (J)" ) );
smenu.query();
switch( smenu.ret ) {
case 0: {
uilist scbms;
for( size_t i = 0; i < cbm_items.size(); i++ ) {
bool enabled = !c.has_bionic( cbm_items[i]->bionic->id );
scbms.addentry( i, enabled, MENU_AUTOASSIGN, "%s", cbm_items[i]->nname( 1 ) );
}
scbms.query();
if( scbms.ret >= 0 ) {
const itype &cbm = *cbm_items[scbms.ret];
const bionic_id &bio = cbm.bionic->id;
constexpr int difficulty = 0;
constexpr int success = 1;
constexpr int level = 99;
c.perform_install( bio, bio->upgraded_bionic, difficulty, success, level, "DEBUG",
bio->canceled_mutations );
}
break;
}
case 1: {
std::vector<bionic_id> bionics = c.get_bionics();
uilist sbionics;
for( size_t i = 0; i < bionics.size(); i++ ) {
sbionics.addentry( i, true, MENU_AUTOASSIGN, "%s", bionics[i]->name.translated() );
}
sbionics.query();
if( sbionics.ret >= 0 ) {
c.remove_bionic( bionics[sbionics.ret] );
}
break;
}
case 2: {
c.clear_bionics();
c.set_power_level( units::from_kilojoule( 0 ) );
c.set_max_power_level( units::from_kilojoule( 0 ) );
break;
}
case 3: {
int new_value = 0;
if( query_int( new_value, _( "Set the value to (in kJ)? Currently: %s" ),
units::display( power_max ) ) ) {
c.set_max_power_level( units::from_kilojoule( new_value ) );
c.set_power_level( c.get_power_level() );
}
break;
}
case 4: {
int new_value = 0;
if( query_int( new_value, _( "Set the value to (in J)? Currently: %s" ),
units::display( power_max ) ) ) {
c.set_max_power_level( units::from_joule( new_value ) );
c.set_power_level( c.get_power_level() );
}
break;
}
case 5: {
int new_value = 0;
if( query_int( new_value, _( "Set the value to (in kJ)? Currently: %s" ),
units::display( power_level ) ) ) {
c.set_power_level( units::from_kilojoule( new_value ) );
}
break;
}
case 6: {
int new_value = 0;
if( query_int( new_value, _( "Set the value to (in J)? Currently: %s" ),
units::display( power_level ) ) ) {
c.set_power_level( units::from_joule( new_value ) );
}
break;
}
default: {
return;
}
}
}
}

class wish_monster_callback: public uilist_callback
{
public:
Expand Down