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

RM13 premature shutdown fix, the Sequel: I need to learn how to Github better #77023

Merged
merged 6 commits into from
Oct 16, 2024
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: 14 additions & 6 deletions src/character_armor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,14 @@ bool Character::armor_absorb( damage_unit &du, item &armor, const bodypart_id &b
}
// if this armor has the flag, try to deduct that much energy from it. If that takes it to 0 energy, turn it off before it absorbs damage.
if( armor.has_flag( flag_USE_POWER_WHEN_HIT ) &&
units::from_kilojoule( du.amount ) > armor.energy_consume( units::from_kilojoule( du.amount ),
pos(), nullptr ) ) {
units::from_kilojoule( du.amount ) > armor.energy_remaining( nullptr, true ) ) {
armor.deactivate( nullptr, false );
add_msg_if_player( _( "Your %s doesn't have enough power and shuts down!" ), armor.tname() );
add_msg_if_player( _( "Your %s doesn't have enough power to absorb the blow and shuts down!" ),
armor.tname() );
} else if( armor.has_flag( flag_USE_POWER_WHEN_HIT ) &&
units::from_kilojoule( du.amount ) < armor.energy_remaining( nullptr, true ) ) {
armor.energy_consume( units::from_kilojoule( du.amount ),
pos(), nullptr );
}
// reduce the damage
// -1 is passed as roll so that each material is rolled individually
Expand All @@ -305,10 +309,14 @@ bool Character::armor_absorb( damage_unit &du, item &armor, const bodypart_id &b
}
// if this armor has the flag, try to deduct that much energy from it. If that takes it to 0 energy, turn it off before it absorbs damage.
if( armor.has_flag( flag_USE_POWER_WHEN_HIT ) &&
units::from_kilojoule( du.amount ) > armor.energy_consume( units::from_kilojoule( du.amount ),
pos(), nullptr ) ) {
units::from_kilojoule( du.amount ) > armor.energy_remaining( nullptr, true ) ) {
armor.deactivate( nullptr, false );
add_msg_if_player( _( "Your %s doesn't have enough power and shuts down!" ), armor.tname() );
add_msg_if_player( _( "Your %s doesn't have enough power to absorb the blow and shuts down!" ),
armor.tname() );
} else if( armor.has_flag( flag_USE_POWER_WHEN_HIT ) &&
units::from_kilojoule( du.amount ) < armor.energy_remaining( nullptr, true ) ) {
armor.energy_consume( units::from_kilojoule( du.amount ),
pos(), nullptr );
}
// reduce the damage
// -1 is passed as roll so that each material is rolled individually
Expand Down
37 changes: 21 additions & 16 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10874,31 +10874,36 @@ bool item::uses_energy() const

units::energy item::energy_remaining( const Character *carrier ) const
{
if( !uses_energy() ) {
return 0_kJ;
}
units::energy ret = 0_kJ;
return energy_remaining( carrier, false );
}

// Future energy based batteries
if( is_vehicle_battery() ) {
ret += energy;
}
units::energy item::energy_remaining( const Character *carrier, bool ignoreExternalSources ) const
{
units::energy ret = 0_kJ;

// Magazine in the item
const item *mag = magazine_current();
if( mag ) {
ret += mag->energy_remaining( carrier );
}

// Power from bionic
if( carrier != nullptr && has_flag( flag_USES_BIONIC_POWER ) ) {
ret += carrier->get_power_level();
}
if( !ignoreExternalSources ) {

// Extra power from UPS
if( carrier != nullptr && has_flag( flag_USE_UPS ) ) {
ret += carrier->available_ups();
}
// Future energy based batteries
if( is_vehicle_battery() ) {
ret += energy;
}

// Power from bionic
if( carrier != nullptr && has_flag( flag_USES_BIONIC_POWER ) ) {
ret += carrier->get_power_level();
}

// Extra power from UPS
if( carrier != nullptr && has_flag( flag_USE_UPS ) ) {
ret += carrier->available_ups();
}
};

// Battery(ammo) contained within
if( is_magazine() ) {
Expand Down
3 changes: 3 additions & 0 deletions src/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -2447,8 +2447,11 @@ class item : public visitable
/**
* Energy available from battery/UPS/bionics
* @param carrier is used for UPS and bionic power.
* Set second parameter to true to ignore vehicle batteries, UPS and bionic power when checking
*/

units::energy energy_remaining( const Character *carrier = nullptr ) const;
units::energy energy_remaining( const Character *carrier, bool ignoreExternalSources ) const;

/**
* Quantity of ammunition currently loaded in tool, gun or auxiliary gunmod.
Expand Down
Loading