From 5aacee86fede719ae6106ea6b6fd075d17cb4f0b Mon Sep 17 00:00:00 2001 From: Fris0uman Date: Wed, 20 Nov 2019 10:10:31 +0100 Subject: [PATCH 1/4] Add Auto start mode to power gen bionics --- data/raw/keybindings.json | 7 +++++++ src/bionics.cpp | 12 ++++++++++++ src/bionics.h | 1 + src/bionics_ui.cpp | 28 +++++++++++++++++++++++++--- src/suffer.cpp | 7 ++++++- 5 files changed, 51 insertions(+), 4 deletions(-) diff --git a/data/raw/keybindings.json b/data/raw/keybindings.json index 44df0239da8d4..566cb21f94429 100644 --- a/data/raw/keybindings.json +++ b/data/raw/keybindings.json @@ -1417,6 +1417,13 @@ "name": "Toggle safe fuel mod", "bindings": [ { "input_method": "keyboard", "key": "s" } ] }, + { + "type": "keybinding", + "id": "TOGGLE_AUTO_START", + "category": "BIONICS", + "name": "Toggle auto start mod", + "bindings": [ { "input_method": "keyboard", "key": "A" } ] + }, { "type": "keybinding", "id": "TOGGLE_EXAMINE", diff --git a/src/bionics.cpp b/src/bionics.cpp index f273797c0bac9..fd9039e6564bd 100644 --- a/src/bionics.cpp +++ b/src/bionics.cpp @@ -2326,6 +2326,18 @@ void bionic::toggle_safe_fuel_mod() } } +void bionic::toggle_auto_start_mod() +{ + if( info().fuel_opts.empty() ) { + return; + } + if( !has_flag( "AUTO_START_ON" ) ) { + set_flag( "AUTO_START_ON" ); + } else { + remove_flag( "AUTO_START_ON" ); + } +} + void bionic::serialize( JsonOut &json ) const { json.start_object(); diff --git a/src/bionics.h b/src/bionics.h index 0a7b8297f06f0..e431439926ac6 100644 --- a/src/bionics.h +++ b/src/bionics.h @@ -164,6 +164,7 @@ struct bionic { bool is_this_fuel_powered( const itype_id &this_fuel ) const; void toggle_safe_fuel_mod(); + void toggle_auto_start_mod(); void serialize( JsonOut &json ) const; void deserialize( JsonIn &jsin ); diff --git a/src/bionics_ui.cpp b/src/bionics_ui.cpp index 1af0f9a76829c..f922126e3601a 100644 --- a/src/bionics_ui.cpp +++ b/src/bionics_ui.cpp @@ -106,9 +106,9 @@ static void draw_bionics_titlebar( const catacurses::window &window, player *p, desc = _( "Reassigning.\nSelect a bionic to reassign or press SPACE to cancel." ); fuel_string.clear(); } else if( mode == ACTIVATING ) { - desc = _( "Activating ! to examine, = to reassign, TAB to switch tabs, s to toggle fuel saving mode." ); + desc = _( "Activating ! to examine, = to reassign, TAB to switch tabs, s to toggle fuel saving mode, A to toggle auto start mode." ); } else if( mode == EXAMINING ) { - desc = _( "Examining ! to activate, = to reassign, TAB to switch tabs, s to toggle fuel saving mode." ); + desc = _( "Examining ! to activate, = to reassign, TAB to switch tabs, s to toggle fuel saving mode, A to toggle auto start mode." ); } int n_pt_y = 0; fold_and_print( window, point( 1, n_pt_y++ ), pwr_str_pos, c_white, desc ); @@ -143,7 +143,10 @@ static std::string build_bionic_poweronly_string( const bionic &bio ) properties.push_back( _( "(incapacitated)" ) ); } if( !bio.has_flag( "SAFE_FUEL_OFF" ) && !bio.info().fuel_opts.empty() ) { - properties.push_back( _( "(fuel saving mode ON)" ) ); + properties.push_back( _( "(fuel saving ON)" ) ); + } + if( bio.has_flag( "AUTO_START_ON" ) && !bio.info().fuel_opts.empty() ) { + properties.push_back( _( "(auto start ON)" ) ); } return enumerate_as_string( properties, enumeration_conjunction::none ); @@ -416,6 +419,7 @@ void player::power_bionics() ctxt.register_action( "CONFIRM" ); ctxt.register_action( "HELP_KEYBINDINGS" ); ctxt.register_action( "TOGGLE_SAFE_FUEL" ); + ctxt.register_action( "TOGGLE_AUTO_START" ); bool recalc = false; bool redraw = true; @@ -532,6 +536,7 @@ void player::power_bionics() bionic *tmp = nullptr; bool confirmCheck = false; bool toggle_safe_fuel = false; + bool toggle_auto_start = false; if( action == "DOWN" ) { redraw = true; @@ -625,6 +630,8 @@ void player::power_bionics() redraw = true; } else if( action == "TOGGLE_SAFE_FUEL" ) { toggle_safe_fuel = true; + } else if( action == "TOGGLE_AUTO_START" ) { + toggle_auto_start = true; } else if( action == "HELP_KEYBINDINGS" ) { redraw = true; } else if( action == "CONFIRM" ) { @@ -647,6 +654,21 @@ void player::power_bionics() } } + + if( toggle_auto_start ) { + auto &bio_list = tab_mode == TAB_ACTIVE ? active : passive; + if( !current_bionic_list->empty() ) { + tmp = bio_list[cursor]; + if( !tmp->info().fuel_opts.empty() ) { + tmp->toggle_auto_start_mod(); + g->refresh_all(); + redraw = true; + } else { + popup( _( "You can't toggle auto start mode on a non fueled CBM." ) ); + } + } + } + //confirmation either occurred by pressing enter where the bionic cursor is, or the hotkey was selected if( confirmCheck ) { auto &bio_list = tab_mode == TAB_ACTIVE ? active : passive; diff --git a/src/suffer.cpp b/src/suffer.cpp index 4515032f678e1..1d56c11f8a6f4 100644 --- a/src/suffer.cpp +++ b/src/suffer.cpp @@ -1473,7 +1473,12 @@ void Character::suffer() } for( size_t i = 0; i < my_bionics->size(); i++ ) { - if( ( *my_bionics )[i].powered ) { + bionic &bio = ( *my_bionics )[i]; + if( calendar::once_every( 1_hours ) && !bio.id->fuel_opts.empty() && + bio.has_flag( "AUTO_START_ON" ) && power_level <= 0_mJ ) { + g->u.activate_bionic( i ); + } + if( bio.powered ) { process_bionic( i ); } } From 41705c0355e114ba59b9d0dae9b300bffc3d8a5f Mon Sep 17 00:00:00 2001 From: Fris0uman Date: Wed, 20 Nov 2019 17:17:29 +0100 Subject: [PATCH 2/4] move from suffer() to process_bionic() --- src/bionics.cpp | 4 ++++ src/suffer.cpp | 9 +-------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/bionics.cpp b/src/bionics.cpp index fd9039e6564bd..ea663a1e60f33 100644 --- a/src/bionics.cpp +++ b/src/bionics.cpp @@ -972,6 +972,10 @@ static bool attempt_recharge( Character &p, bionic &bio, units::energy &amount, void Character::process_bionic( int b ) { bionic &bio = ( *my_bionics )[b]; + if( calendar::once_every( 1_hours ) && !bio.id->fuel_opts.empty() && + bio.has_flag( "AUTO_START_ON" ) && power_level <= 0_mJ ) { + g->u.activate_bionic( b ); + } // Only powered bionics should be processed if( !bio.powered ) { return; diff --git a/src/suffer.cpp b/src/suffer.cpp index 1d56c11f8a6f4..165f3bee055fa 100644 --- a/src/suffer.cpp +++ b/src/suffer.cpp @@ -1473,14 +1473,7 @@ void Character::suffer() } for( size_t i = 0; i < my_bionics->size(); i++ ) { - bionic &bio = ( *my_bionics )[i]; - if( calendar::once_every( 1_hours ) && !bio.id->fuel_opts.empty() && - bio.has_flag( "AUTO_START_ON" ) && power_level <= 0_mJ ) { - g->u.activate_bionic( i ); - } - if( bio.powered ) { - process_bionic( i ); - } + process_bionic( i ); } for( std::pair &mut : my_mutations ) { From b65ba96607880b11613d1793d6d92ae93cf18a15 Mon Sep 17 00:00:00 2001 From: Fris0uman <41293484+Fris0uman@users.noreply.github.com> Date: Wed, 20 Nov 2019 18:24:45 +0100 Subject: [PATCH 3/4] Update src/bionics_ui.cpp Co-Authored-By: Anton Burmistrov --- src/bionics_ui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bionics_ui.cpp b/src/bionics_ui.cpp index f922126e3601a..9ec6887c44db0 100644 --- a/src/bionics_ui.cpp +++ b/src/bionics_ui.cpp @@ -664,7 +664,7 @@ void player::power_bionics() g->refresh_all(); redraw = true; } else { - popup( _( "You can't toggle auto start mode on a non fueled CBM." ) ); + popup( _( "You can't toggle auto start mode on a non-fueled CBM." ) ); } } } From e516d5c840a8f42c152a9e16a749b4612df36de4 Mon Sep 17 00:00:00 2001 From: Fris0uman Date: Wed, 20 Nov 2019 18:25:20 +0100 Subject: [PATCH 4/4] add - --- src/bionics_ui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bionics_ui.cpp b/src/bionics_ui.cpp index 9ec6887c44db0..8ea1a69c4e56d 100644 --- a/src/bionics_ui.cpp +++ b/src/bionics_ui.cpp @@ -649,7 +649,7 @@ void player::power_bionics() g->refresh_all(); redraw = true; } else { - popup( _( "You can't toggle fuel saving mode on a non fueled CBM." ) ); + popup( _( "You can't toggle fuel saving mode on a non-fueled CBM." ) ); } }