Skip to content

Commit

Permalink
Add support for specify monster armor coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua-Chin committed Sep 2, 2021
1 parent c11072c commit db40cf8
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 13 deletions.
3 changes: 3 additions & 0 deletions data/json/monsters/misc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
"material": [ "flesh" ],
"symbol": "X",
"color": "white",
"armor_coverage": 50,
"armor_bullet": 100,
"unarmored_bullet": 10,
"aggression": 100,
"morale": 100,
"melee_cut": 0,
Expand Down
18 changes: 13 additions & 5 deletions src/damage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,20 @@ resistances::resistances( const item &armor, bool to_self )
}
}
}
resistances::resistances( monster &monster ) : resistances()
resistances::resistances( monster &monster, bool unarmored ) : resistances()
{
set_resist( damage_type::BASH, monster.type->armor_bash );
set_resist( damage_type::CUT, monster.type->armor_cut );
set_resist( damage_type::STAB, monster.type->armor_stab );
set_resist( damage_type::BULLET, monster.type->armor_bullet );
if( unarmored ) {
set_resist( damage_type::BASH, monster.type->unarmored_bash );
set_resist( damage_type::CUT, monster.type->unarmored_cut );
set_resist( damage_type::STAB, monster.type->unarmored_stab );
set_resist( damage_type::BULLET, monster.type->unarmored_bullet );
} else {
set_resist( damage_type::BASH, monster.type->armor_bash );
set_resist( damage_type::CUT, monster.type->armor_cut );
set_resist( damage_type::STAB, monster.type->armor_stab );
set_resist( damage_type::BULLET, monster.type->armor_bullet );
}
// Acid and fire have 100% coverage
set_resist( damage_type::ACID, monster.type->armor_acid );
set_resist( damage_type::HEAT, monster.type->armor_fire );
}
Expand Down
2 changes: 1 addition & 1 deletion src/damage.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ struct resistances {

// If to_self is true, we want armor's own resistance, not one it provides to wearer
explicit resistances( const item &armor, bool to_self = false );
explicit resistances( monster &monster );
explicit resistances( monster &monster, bool unarmored = false );
void set_resist( damage_type dt, float amount );
float type_resist( damage_type dt ) const;

Expand Down
3 changes: 2 additions & 1 deletion src/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1492,7 +1492,8 @@ void monster::absorb_hit( const bodypart_id &, damage_instance &dam )
for( auto &elem : dam.damage_units ) {
add_msg_debug( debugmode::DF_MONSTER, "Dam Type: %s :: Ar Pen: %.1f :: Armor Mult: %.1f",
name_by_dt( elem.type ), elem.res_pen, elem.res_mult );
elem.amount -= std::min( resistances( *this ).get_effective_resist( elem ) +
bool unarmored = rng( 1, 100 ) > this->type->armor_coverage;
elem.amount -= std::min( resistances( *this, unarmored ).get_effective_resist( elem ) +
get_worn_armor_val( elem.type ), elem.amount );
}
}
Expand Down
19 changes: 19 additions & 0 deletions src/monstergenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,19 @@ void MonsterGenerator::finalize_mtypes()
mon.armor_fire = 0;
}

if( mon.unarmored_bash < 0 ) {
mon.unarmored_bash = 0;
}
if( mon.unarmored_cut < 0 ) {
mon.unarmored_cut = 0;
}
if( mon.unarmored_stab < 0 ) {
mon.unarmored_stab = mon.unarmored_cut * 0.8;
}
if( mon.unarmored_bullet < 0 ) {
mon.unarmored_bullet = 0;
}

// Lower bound for hp scaling
mon.hp = std::max( mon.hp, 1 );

Expand Down Expand Up @@ -710,13 +723,19 @@ void mtype::load( const JsonObject &jo, const std::string &src )
assign( jo, "grab_strength", grab_strength, strict, 0 );

assign( jo, "dodge", sk_dodge, strict, 0 );
assign( jo, "armor_coverage", armor_coverage, strict, 0, 100 );
assign( jo, "armor_bash", armor_bash, strict, 0 );
assign( jo, "armor_cut", armor_cut, strict, 0 );
assign( jo, "armor_bullet", armor_bullet, strict, 0 );
assign( jo, "armor_stab", armor_stab, strict, 0 );
assign( jo, "armor_acid", armor_acid, strict, 0 );
assign( jo, "armor_fire", armor_fire, strict, 0 );

assign( jo, "unarmored_bash", unarmored_bash, strict, 0 );
assign( jo, "unarmored_cut", unarmored_cut, strict, 0 );
assign( jo, "unarmored_bullet", unarmored_bullet, strict, 0 );
assign( jo, "unarmored_stab", unarmored_stab, strict, 0 );

optional( jo, was_loaded, "bleed_rate", bleed_rate, 100 );

assign( jo, "vision_day", vision_day, strict, 0 );
Expand Down
18 changes: 12 additions & 6 deletions src/mtype.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,12 +321,18 @@ struct mtype {
int sk_dodge = 0; /** dodge skill */

/** If unset (-1) then values are calculated automatically from other properties */
int armor_bash = -1; /** innate armor vs. bash */
int armor_cut = -1; /** innate armor vs. cut */
int armor_stab = -1; /** innate armor vs. stabbing */
int armor_bullet = -1; /** innate armor vs. bullet */
int armor_acid = -1; /** innate armor vs. acid */
int armor_fire = -1; /** innate armor vs. fire */
int armor_coverage = 100; /** percent of the monster covered by armor */
int armor_bash = -1; /** innate armor vs. bash */
int armor_cut = -1; /** innate armor vs. cut */
int armor_stab = -1; /** innate armor vs. stabbing */
int armor_bullet = -1; /** innate armor vs. bullet */
int armor_acid = -1; /** innate armor vs. acid */
int armor_fire = -1; /** innate armor vs. fire */

int unarmored_bash = -1; /** unarmored resistance vs. bash */
int unarmored_cut = -1; /** unarmored resistance vs. cut */
int unarmored_stab = -1; /** unarmored resistance vs. stabbing */
int unarmored_bullet = -1; /** unarmored resistance vs. bullet */

// Bleed rate in percent, 0 makes the monster immune to bleeding
int bleed_rate = 100;
Expand Down

0 comments on commit db40cf8

Please sign in to comment.