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

Fix CBM not drawing power #34862

Merged
merged 5 commits into from
Oct 22, 2019
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
2 changes: 1 addition & 1 deletion src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3101,7 +3101,7 @@ void activity_handlers::operation_do_turn( player_activity *act, player *p )

if( p->has_bionic( bid ) ) {
p->perform_uninstall( bid, act->values[0], act->values[1],
act->values[2], act->values[3] );
units::from_millijoule( act->values[2] ), act->values[3] );
} else {
debugmsg( _( "Tried to uninstall %s, but you don't have this bionic installed." ),
act->str_values[cbm_id] );
Expand Down
21 changes: 11 additions & 10 deletions src/bionics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -900,10 +900,11 @@ bool player::burn_fuel( int b, bool start )
* @param rate divides the number of turns we may charge (rate of 2 discharges in half the time).
* @return indicates whether we successfully charged the bionic.
*/
static bool attempt_recharge( player &p, bionic &bio, int &amount, int factor = 1, int rate = 1 )
static bool attempt_recharge( player &p, bionic &bio, units::energy &amount, int factor = 1,
int rate = 1 )
{
const bionic_data &info = bio.info();
const int armor_power_cost = 1;
const units::energy armor_power_cost = 1_kJ;
units::energy power_cost = info.power_over_time * factor;
bool recharged = false;

Expand All @@ -915,12 +916,12 @@ static bool attempt_recharge( player &p, bionic &bio, int &amount, int factor =
return w.active && w.is_power_armor();
} );
if( !powered_armor ) {
power_cost -= units::from_kilojoule( armor_power_cost ) * factor;
power_cost -= armor_power_cost * factor;
}
}
if( p.get_power_level() >= power_cost ) {
// Set the recharging cost and charge the bionic.
amount = units::to_kilojoule( power_cost );
amount = power_cost;
// This is our first turn of charging, so subtract a turn from the recharge delay.
bio.charge_timer = info.charge_time - rate;
recharged = true;
Expand Down Expand Up @@ -953,7 +954,7 @@ void player::process_bionic( int b )
bio.charge_timer = bio.info().charge_time;
} else {
// Try to recharge our bionic if it is made for it
int cost = 0;
units::energy cost = 0_mJ;
bool recharged = attempt_recharge( *this, bio, cost, discharge_factor, discharge_rate );
if( !recharged ) {
// No power to recharge, so deactivate
Expand All @@ -963,8 +964,8 @@ void player::process_bionic( int b )
deactivate_bionic( b, true );
return;
}
if( cost ) {
mod_power_level( units::from_kilojoule( -cost ) );
if( cost > 0_mJ ) {
mod_power_level( -cost );
}
}
}
Expand Down Expand Up @@ -1461,7 +1462,7 @@ bool player::uninstall_bionic( const bionic_id &b_id, player &installer, bool au
return true;
}

void player::perform_uninstall( bionic_id bid, int difficulty, int success, int power_lvl,
void player::perform_uninstall( bionic_id bid, int difficulty, int success, units::energy power_lvl,
int pl_skill )
{
if( success > 0 ) {
Expand All @@ -1474,7 +1475,7 @@ void player::perform_uninstall( bionic_id bid, int difficulty, int success, int
remove_bionic( bid );

// remove power bank provided by bionic
mod_max_power_level( -units::from_kilojoule( power_lvl ) );
mod_max_power_level( -power_lvl );

item cbm( "burnt_out_bionic" );
if( item::type_is_defined( bid.c_str() ) ) {
Expand Down Expand Up @@ -1686,7 +1687,7 @@ bool player::install_bionics( const itype &type, player &installer, bool autodoc

activity.values.push_back( difficulty );
activity.values.push_back( success );
activity.values.push_back( units::to_kilojoule( bionics[bioid].capacity ) );
activity.values.push_back( units::to_millijoule( bionics[bioid].capacity ) );
activity.values.push_back( pl_skill );
activity.str_values.push_back( "install" );
activity.str_values.push_back( "" );
Expand Down
3 changes: 2 additions & 1 deletion src/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,8 @@ class player : public Character
bool uninstall_bionic( const bionic_id &b_id, player &installer, bool autodoc = false,
int skill_level = -1 );
/**Succes or failure of removal happens here*/
void perform_uninstall( bionic_id bid, int difficulty, int success, int power_lvl, int pl_skill );
void perform_uninstall( bionic_id bid, int difficulty, int success, units::energy power_lvl,
int pl_skill );
/**Used by monster to perform surgery*/
bool uninstall_bionic( const bionic &target_cbm, monster &installer, player &patient,
float adjusted_skill, bool autodoc = false );
Expand Down