Skip to content

Commit

Permalink
Merge pull request CleverRaven#51633 from kevingranade/big-energy
Browse files Browse the repository at this point in the history
Default energy to using int64_t as an underlying type
  • Loading branch information
Rivet-the-Zombie authored Sep 16, 2021
2 parents 401cc44 + 2c06c5f commit 3c8d674
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 13 deletions.
5 changes: 3 additions & 2 deletions src/bionics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1570,7 +1570,7 @@ material_id Character::find_remote_fuel( bool look_only )

if( cable->get_var( "state" ) == "UPS_link" ) {
if( !look_only ) {
int remote_battery = 0;
int64_t remote_battery = 0;
for( const item *i : all_items_with_flag( flag_IS_UPS ) ) {
if( i->get_var( "cable" ) == "plugged_in" ) {
remote_battery = i->ammo_remaining();
Expand Down Expand Up @@ -2445,7 +2445,8 @@ ret_val<bool> Character::is_installable( const item_location &loc, const bool by
return ret_val<bool>::make_failure( _( "Superior version installed." ) );
} else if( is_npc() && !bid->has_flag( json_flag_BIONIC_NPC_USABLE ) ) {
return ret_val<bool>::make_failure( _( "CBM not compatible with patient." ) );
} else if( units::energy_max - get_max_power_level() < bid->capacity ) {
} else if( units::energy( std::numeric_limits<int>::max(), units::energy::unit_type{} ) -
get_max_power_level() < bid->capacity ) {
return ret_val<bool>::make_failure( _( "Max power capacity already reached." ) );
}

Expand Down
8 changes: 4 additions & 4 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7798,22 +7798,22 @@ int Character::available_ups() const
return available_charges;
}

int Character::consume_ups( int qty, const int radius )
int Character::consume_ups( int64_t qty, const int radius )
{
const int wanted_qty = qty;
const int64_t wanted_qty = qty;

// UPS from mounted mech
if( qty != 0 && is_mounted() && mounted_creature.get()->has_flag( MF_RIDEABLE_MECH ) &&
mounted_creature.get()->battery_item ) {
auto *mons = mounted_creature.get();
int power_drain = std::min( mons->battery_item->ammo_remaining(), qty );
int64_t power_drain = std::min( static_cast<int64_t>( mons->battery_item->ammo_remaining() ), qty );
mons->use_mech_power( -power_drain );
qty -= std::min( qty, power_drain );
}

// UPS from bionic
if( qty != 0 && has_power() && has_active_bionic( bio_ups ) ) {
int bio = std::min( units::to_kilojoule( get_power_level() ), qty );
int64_t bio = std::min( units::to_kilojoule( get_power_level() ), qty );
mod_power_level( units::from_kilojoule( -bio ) );
qty -= std::min( qty, bio );
}
Expand Down
2 changes: 1 addition & 1 deletion src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -2332,7 +2332,7 @@ class Character : public Creature, public visitable
* @param qty Number of charges (kJ)
* @return amount of UPS consumed which will be between 0 and qty
*/
int consume_ups( int qty, int radius = -1 );
int consume_ups( int64_t qty, int radius = -1 );

/**
* Use charges in character inventory.
Expand Down
2 changes: 1 addition & 1 deletion src/condition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,7 @@ std::function<int( const T & )> conditional_t<T>::get_get_int( const JsonObject
if( power_max == 0 ) {
return 0; //Default value if character does not have power, avoids division with 0.
} else {
return ( d.actor( is_npc )->power_cur().value() * 100 ) / power_max;
return static_cast<int>( d.actor( is_npc )->power_cur().value() * 100 ) / power_max;
}
};
} else if( checked_value == "morale" ) {
Expand Down
3 changes: 2 additions & 1 deletion src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8492,7 +8492,8 @@ int item::ammo_consume( int qty, const tripoint &pos, Character *carrier )

// Consume bio pwr directly
if( carrier != nullptr && has_flag( flag_USES_BIONIC_POWER ) ) {
int bio_used = std::min( units::to_kilojoule( carrier->get_power_level() ), qty );
int bio_used = std::min( static_cast < int>( units::to_kilojoule( carrier->get_power_level() ) ),
qty );
carrier->mod_power_level( -units::from_kilojoule( bio_used ) );
qty -= bio_used;
}
Expand Down
3 changes: 2 additions & 1 deletion src/iuse_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4027,7 +4027,8 @@ ret_val<bool> install_bionic_actor::can_use( const Character &p, const item &it,
} else if( it.has_fault( fault_bionic_salvaged ) ) {
return ret_val<bool>::make_failure(
_( "This CBM is already deployed. You need to reset it to factory state." ) );
} else if( units::energy_max - p.get_max_power_level() < bid->capacity ) {
} else if( units::energy( std::numeric_limits<int>::max(), units::energy::unit_type{} ) -
p.get_max_power_level() < bid->capacity ) {
return ret_val<bool>::make_failure( _( "Max power capacity already reached" ) );
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/units_fwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class energy_in_millijoule_tag
{
};

using energy = quantity<int, energy_in_millijoule_tag>;
using energy = quantity<std::int64_t, energy_in_millijoule_tag>;

class money_in_cent_tag
{
Expand Down
6 changes: 4 additions & 2 deletions src/visitable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -789,11 +789,13 @@ static int charges_of_internal( const T &self, const M &main, const itype_id &id
} );

if( found_tool_with_UPS && qty < limit && get_player_character().has_active_bionic( bio_ups ) ) {
qty = sum_no_wrap( qty, units::to_kilojoule( get_player_character().get_power_level() ) );
qty = sum_no_wrap( qty, static_cast<int>( units::to_kilojoule(
get_player_character().get_power_level() ) ) );
}

if( found_bionic_tool ) {
qty = sum_no_wrap( qty, units::to_kilojoule( get_player_character().get_power_level() ) );
qty = sum_no_wrap( qty, static_cast<int>( units::to_kilojoule(
get_player_character().get_power_level() ) ) );
}

if( qty < limit && found_tool_with_UPS ) {
Expand Down

0 comments on commit 3c8d674

Please sign in to comment.