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

Add Auto start mode to power gen bionics #35620

Merged
merged 4 commits into from
Nov 22, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
7 changes: 7 additions & 0 deletions data/raw/keybindings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
16 changes: 16 additions & 0 deletions src/bionics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, but with this conditions this feature is useless. It needs to be at least every minute and somewhere between 66% - 80% of max power.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I'm setting up a menu to choose the threshold, I just need to figure out the time interval thing, because trying to turn on your CBM every minutes when you don't have fuel for it is very spammy.

g->u.activate_bionic( b );
}
// Only powered bionics should be processed
if( !bio.powered ) {
return;
Expand Down Expand Up @@ -2326,6 +2330,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();
Expand Down
1 change: 1 addition & 0 deletions src/bionics.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
28 changes: 25 additions & 3 deletions src/bionics_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = _( "<color_green>Activating</color> <color_yellow>!</color> to examine, <color_yellow>=</color> to reassign, <color_yellow>TAB</color> to switch tabs, <color_yellow>s</color> to toggle fuel saving mode." );
desc = _( "<color_green>Activating</color> <color_yellow>!</color> to examine, <color_yellow>=</color> to reassign, <color_yellow>TAB</color> to switch tabs, <color_yellow>s</color> to toggle fuel saving mode, <color_yellow>A</color> to toggle auto start mode." );
} else if( mode == EXAMINING ) {
desc = _( "<color_light_blue>Examining</color> <color_yellow>!</color> to activate, <color_yellow>=</color> to reassign, <color_yellow>TAB</color> to switch tabs, <color_yellow>s</color> to toggle fuel saving mode." );
desc = _( "<color_light_blue>Examining</color> <color_yellow>!</color> to activate, <color_yellow>=</color> to reassign, <color_yellow>TAB</color> to switch tabs, <color_yellow>s</color> to toggle fuel saving mode, <color_yellow>A</color> 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 );
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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" ) {
Expand All @@ -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." ) );
Fris0uman marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

//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;
Expand Down
4 changes: 1 addition & 3 deletions src/suffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1473,9 +1473,7 @@ void Character::suffer()
}

for( size_t i = 0; i < my_bionics->size(); i++ ) {
if( ( *my_bionics )[i].powered ) {
process_bionic( i );
}
process_bionic( i );
}

for( std::pair<const trait_id, Character::trait_data> &mut : my_mutations ) {
Expand Down