Skip to content

Commit

Permalink
Functionality for armor draining energy when taking damage (#66374)
Browse files Browse the repository at this point in the history
* Flag to use charges when hit

* use power when hit

* use power when hit flag

* Update flag.cpp

* Update flag.h

* Update tool_armor.json

* Update character_armor.cpp

* Update character_armor.cpp

* Update character_armor.cpp

* handle running out of energy

* Update src/character_armor.cpp

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Update src/character_armor.cpp

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
anoobindisguise and github-actions[bot] authored Jun 26, 2023
1 parent b9ee35e commit f13d34a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
5 changes: 5 additions & 0 deletions data/json/flags.json
Original file line number Diff line number Diff line change
Expand Up @@ -2223,5 +2223,10 @@
"id": "REBREATHER_CART",
"type": "json_flag",
"info": "A filter for a rebreather."
},
{
"id": "USE_POWER_WHEN_HIT",
"type": "json_flag",
"info": "This armor <info>expends energy when hit</info>."
}
]
5 changes: 3 additions & 2 deletions data/json/items/tool_armor.json
Original file line number Diff line number Diff line change
Expand Up @@ -1343,10 +1343,11 @@
"USE_UPS",
"NO_UNLOAD",
"COMBAT_TOGGLEABLE",
"UNBREAKABLE_MELEE"
"UNBREAKABLE_MELEE",
"USE_POWER_WHEN_HIT"
],
"material": [ "hyperweave_on", "carbide" ],
"power_draw": "250 W",
"power_draw": "100 W",
"revert_to": "rm13_armor",
"use_action": [ "RM13ARMOR_ON" ],
"environmental_protection": 40,
Expand Down
16 changes: 14 additions & 2 deletions src/character_armor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,13 @@ bool Character::armor_absorb( damage_unit &du, item &armor, const bodypart_id &b
if( roll > armor.get_coverage( sbp, ctype ) ) {
return false;
}

// 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 ) ) {
armor.deactivate( nullptr, false );
add_msg_if_player( _( "Your %s doesn't have enough power and shuts down!" ), armor.tname() );
}
// reduce the damage
// -1 is passed as roll so that each material is rolled individually
armor.mitigate_damage( du, sbp, -1 );
Expand All @@ -267,7 +273,13 @@ bool Character::armor_absorb( damage_unit &du, item &armor, const bodypart_id &b
if( roll > armor.get_coverage( bp, ctype ) ) {
return false;
}

// 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 ) ) {
armor.deactivate( nullptr, false );
add_msg_if_player( _( "Your %s doesn't have enough power and shuts down!" ), armor.tname() );
}
// reduce the damage
// -1 is passed as roll so that each material is rolled individually
armor.mitigate_damage( du, bp, -1 );
Expand Down
1 change: 1 addition & 0 deletions src/flag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ const flag_id flag_URSINE_HONEY( "URSINE_HONEY" );
const flag_id flag_USES_BIONIC_POWER( "USES_BIONIC_POWER" );
const flag_id flag_USE_EAT_VERB( "USE_EAT_VERB" );
const flag_id flag_USE_PLAYER_ENERGY( "USE_PLAYER_ENERGY" );
const flag_id flag_USE_POWER_WHEN_HIT( "USE_POWER_WHEN_HIT" );
const flag_id flag_USE_UPS( "USE_UPS" );
const flag_id flag_VARSIZE( "VARSIZE" );
const flag_id flag_VEHICLE( "VEHICLE" );
Expand Down
1 change: 1 addition & 0 deletions src/flag.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ extern const flag_id flag_URSINE_HONEY;
extern const flag_id flag_USES_BIONIC_POWER;
extern const flag_id flag_USE_EAT_VERB;
extern const flag_id flag_USE_PLAYER_ENERGY;
extern const flag_id flag_USE_POWER_WHEN_HIT;
extern const flag_id flag_USE_UPS;
extern const flag_id flag_VARSIZE;
extern const flag_id flag_VEHICLE;
Expand Down

0 comments on commit f13d34a

Please sign in to comment.