From f6b7621858fc8463b21dccec13c40ccd7a1da984 Mon Sep 17 00:00:00 2001 From: LISPCoC Date: Sat, 18 Nov 2023 17:28:23 +0900 Subject: [PATCH 1/4] avoid friendly fire --- src/ballistics.cpp | 5 +++++ src/character.cpp | 6 ++++++ src/character.h | 1 + src/creature.h | 3 +++ src/magic_enchantment.cpp | 1 + src/magic_enchantment.h | 1 + 6 files changed, 17 insertions(+) diff --git a/src/ballistics.cpp b/src/ballistics.cpp index 4c69e4d68308e..cc28a0ed3717f 100644 --- a/src/ballistics.cpp +++ b/src/ballistics.cpp @@ -424,6 +424,11 @@ dealt_projectile_attack projectile_attack( const projectile &proj_arg, const tri // Or was just IFFing, giving lots of warnings and time to get out of the line of fire continue; } + // avoid friendly fire + if( critter->attitude_to( *origin ) == Creature::Attitude::FRIENDLY && + origin->avoid_friendly_fire() ) { + continue; + } attack.missed_by = cur_missed_by; bool print_messages = true; // If the attack is shot, once we're past point-blank, diff --git a/src/character.cpp b/src/character.cpp index 5821c067d71f1..69efc82ed0b62 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -2015,6 +2015,12 @@ bool Character::uncanny_dodge() return false; } +bool Character::avoid_friendly_fire() const +{ + double chance = enchantment_cache->modify_value( enchant_vals::mod::AVOID_FRIENDRY_FIRE, 0.0 ); + return rng( 0, 99 ) < chance * 100.0; +} + void Character::handle_skill_warning( const skill_id &id, bool force_warning ) { //remind the player intermittently that no skill gain takes place diff --git a/src/character.h b/src/character.h index 3545f69d3e64e..517e5e165092a 100644 --- a/src/character.h +++ b/src/character.h @@ -816,6 +816,7 @@ class Character : public Creature, public visitable int get_spell_resist() const override; /** Handles the uncanny dodge bionic and effects, returns true if the player successfully dodges */ bool uncanny_dodge() override; + bool avoid_friendly_fire() const override; float get_hit_base() const override; /** Returns the player's sight range */ diff --git a/src/creature.h b/src/creature.h index 762f9ee80203e..c6d7cf49cbf5b 100644 --- a/src/creature.h +++ b/src/creature.h @@ -745,6 +745,9 @@ class Creature : public viewer virtual bool uncanny_dodge() { return false; } + virtual bool avoid_friendly_fire() const { + return false; + } void set_reachable_zone( int zone ) { reachable_zone = zone; } diff --git a/src/magic_enchantment.cpp b/src/magic_enchantment.cpp index fabfa5c0231bc..176f9782048ea 100644 --- a/src/magic_enchantment.cpp +++ b/src/magic_enchantment.cpp @@ -149,6 +149,7 @@ namespace io case enchant_vals::mod::EVASION: return "EVASION"; case enchant_vals::mod::OVERKILL_DAMAGE: return "OVERKILL_DAMAGE"; case enchant_vals::mod::RANGE: return "RANGE"; + case enchant_vals::mod::AVOID_FRIENDRY_FIRE: return "AVOID_FRIENDRY_FIRE"; case enchant_vals::mod::NUM_MOD: break; } cata_fatal( "Invalid enchant_vals::mod" ); diff --git a/src/magic_enchantment.h b/src/magic_enchantment.h index 02df3e48d67d0..8870d571732a0 100644 --- a/src/magic_enchantment.h +++ b/src/magic_enchantment.h @@ -126,6 +126,7 @@ enum class mod : int { EVASION, OVERKILL_DAMAGE, RANGE, + AVOID_FRIENDRY_FIRE, NUM_MOD }; } // namespace enchant_vals From 21b5e1487bc617c075e5bfa85278b97fd2275e8a Mon Sep 17 00:00:00 2001 From: LISPCoC Date: Sat, 18 Nov 2023 17:43:09 +0900 Subject: [PATCH 2/4] doc --- doc/MAGIC.md | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/MAGIC.md b/doc/MAGIC.md index ea7523eea0aab..fa5dae1bf58ab 100644 --- a/doc/MAGIC.md +++ b/doc/MAGIC.md @@ -777,6 +777,7 @@ Character status value | Description `ARMOR_STAB` | `ATTACK_NOISE` | Affects the amount of noise you make while melee attacking. `ATTACK_SPEED` | Affects attack speed of item even if it's not the one you're wielding. +`AVOID_FRIENDRY_FIRE` | Flat chance for your character to avoid friendry fire if there is a friend in the line of fire. From 0.0 (no chance) to 1.0 (never frindly fire). `BIONIC_POWER` | `BONUS_BLOCK` | Affects the number of blocks you can perform. `BONUS_DODGE` | Affects the number of dodges you can perform. From b87d1cf33e8bf4f9404d618d66ee013c0ed3b3c7 Mon Sep 17 00:00:00 2001 From: LISPCoC Date: Sat, 18 Nov 2023 18:12:41 +0900 Subject: [PATCH 3/4] fix --- src/ballistics.cpp | 2 +- src/character.h | 2 +- src/creature.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ballistics.cpp b/src/ballistics.cpp index cc28a0ed3717f..072c8437044d3 100644 --- a/src/ballistics.cpp +++ b/src/ballistics.cpp @@ -426,7 +426,7 @@ dealt_projectile_attack projectile_attack( const projectile &proj_arg, const tri } // avoid friendly fire if( critter->attitude_to( *origin ) == Creature::Attitude::FRIENDLY && - origin->avoid_friendly_fire() ) { + origin->check_avoid_friendly_fire() ) { continue; } attack.missed_by = cur_missed_by; diff --git a/src/character.h b/src/character.h index 517e5e165092a..25f46403f979d 100644 --- a/src/character.h +++ b/src/character.h @@ -816,7 +816,7 @@ class Character : public Creature, public visitable int get_spell_resist() const override; /** Handles the uncanny dodge bionic and effects, returns true if the player successfully dodges */ bool uncanny_dodge() override; - bool avoid_friendly_fire() const override; + bool check_avoid_friendly_fire() const override; float get_hit_base() const override; /** Returns the player's sight range */ diff --git a/src/creature.h b/src/creature.h index c6d7cf49cbf5b..4351bda1e6b30 100644 --- a/src/creature.h +++ b/src/creature.h @@ -745,7 +745,7 @@ class Creature : public viewer virtual bool uncanny_dodge() { return false; } - virtual bool avoid_friendly_fire() const { + virtual bool check_avoid_friendly_fire() const { return false; } void set_reachable_zone( int zone ) { From ceb68dba23fb1095f72ca7f70d14df9cd969f12a Mon Sep 17 00:00:00 2001 From: LISPCoC Date: Sat, 18 Nov 2023 20:48:57 +0900 Subject: [PATCH 4/4] fix --- src/character.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/character.cpp b/src/character.cpp index 69efc82ed0b62..248c1058bb975 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -2015,7 +2015,7 @@ bool Character::uncanny_dodge() return false; } -bool Character::avoid_friendly_fire() const +bool Character::check_avoid_friendly_fire() const { double chance = enchantment_cache->modify_value( enchant_vals::mod::AVOID_FRIENDRY_FIRE, 0.0 ); return rng( 0, 99 ) < chance * 100.0;