Up-to-Date Stabbing Mechanisms?


If it doesn't fit anywhere else, it belongs here. Also, come here if you just need to get hammered.

Tartarus Sorceror

Posts: 1822

Joined: Thursday, 31st May 2012, 15:45

Post Sunday, 5th April 2020, 19:06

Up-to-Date Stabbing Mechanisms?

I want to know how stabbing works under the hood in 0.25. The wiki article is for 0.17 and refers to four stabbing tiers, but there have only been two stabbing tiers since 0.19. LearnDb is even more obsolete since it refers to long blades and one-handed polearms as having a distinct stab multiplier, but weapons have been treated as Sbl/non-SBl for stabs since 0.16.

What I've gathered is the following, but I'd like to confirm the algorithm and learn the mathematical functions.

  • Short blades get a damage bonus added to the weapon's damage. This is a function of DEX,SBl and Stealth skills, is halved if the weapon isn't a dagger, then capped at 30.
  • There are two stab tiers: 1 is Sleep/Paralysis/Petrified, and 4 is confused, distracted, netted or webbed, enslaved or ally, attacker invisible, petrifying.
  • All weapons get a stabbing multiplier, applied to the weapon damage roll after Str, Fgt, Weapon Skill, Might/Berserk, and Slaying are accounted for, plus the Sbl damage bonus. This is a function of weapon skill and Stealth and then divided by stab tier.
  • Short blades may still have a second stab multiplier that is multiplied onto the stab multiplier of all weapons that is also a function of SBl, Sth and stab tier.

Might someone know the answer to this, or point me please to the correct place in the code for me to look into this?

Thank you!
Won (52). Remaining (15): 5 species: Ba, Fe, Mu, Na, Op; 5 Backgrounds: AM, Wr, Su, AE, Ar; 5 gods: Jiyv, newNem, WJC, newSif, newFedh

Slime Squisher

Posts: 368

Joined: Thursday, 11th April 2013, 21:07

Post Monday, 6th April 2020, 05:10

Re: Up-to-Date Stabbing Mechanisms?

In general, the easiest way to find things like this is to search the git repository. One way to do that is to make a local clone of the repo, and then run grep.

You can usually start by searching for a string that might relate to what you're looking for, and refine your searches from there until you find the relevant code. If there's a lot of matches, you can pipe grep back into grep to search the matches for another match, like so:

  Code:
git clone git://github.com/crawl/crawl.git crawl
cd crawl
git grep -n "sleep" | grep stab

This gets us to line 1781 of attack.cc, right next to attack::player_stab_check() , which is a pretty good spot to dive into what you're looking for.

Each stab check appears to be called from melee_attack::attack() in melee-attack.cc: about halfway down that function, you can find the initial call to player_stab_check().

Another grep for "find_stab_type" takes us over to fight.cc. This function contains the conditions for various stabs like STAB_SLEEPING and STAB_HELD_IN_NET, and sets up the stab_type accordingly.

It looks like player_stab_check() sets up the stab_attempt and the stab_bonus, based on the stab_type.

These are later checked by attack::player_stab(), which goes on to call player_stab_weapon_bonus() if there is a stab_bonus.

You might need a couple of further greps for things like "stab_bonus_denom" which is hiding out over in fight.cc, or melee_attack::player_good_stab(), which can be found in melee-attack.cc.


Some things that the code checks that you appear to be missing in the OP:
MUT_PAWS (as in Felid, I guess?), which appears to allow "good" stabs, but not "extra good" stabs,
the unrand hood of the assassin (which appears to allow "good" stabs, but not "extra good" stabs, with UC or any non-ranged weapon),
the unrand spriggan's knife (which appears to upgrade would-be stabs to STAB_SLEEPING),
potions of stabbing (which appear to upgrade would-be stabs to STAB_SLEEPING on a coinflip),
and that Dex affects damage for both "good" and "extra good" stabs.

Please read the code for full details: I've probably omitted some things in my half-asleep attempt at plain-english translation.

For this message the author Implojin has received thanks:
MainiacJoe

Tartarus Sorceror

Posts: 1822

Joined: Thursday, 31st May 2012, 15:45

Post Monday, 6th April 2020, 14:40

Re: Up-to-Date Stabbing Mechanisms?

Thank you so much for the extremely helpful response!
Won (52). Remaining (15): 5 species: Ba, Fe, Mu, Na, Op; 5 Backgrounds: AM, Wr, Su, AE, Ar; 5 gods: Jiyv, newNem, WJC, newSif, newFedh

Tartarus Sorceror

Posts: 1822

Joined: Thursday, 31st May 2012, 15:45

Post Monday, 6th April 2020, 21:50

Re: Up-to-Date Stabbing Mechanisms?

Here is my conclusion for the stabbing algorithm.

  1. Abort (no stab) if:
    • Not a melee attack (reaching polearm okay)
    • Player is confused
    • Target cannot be seen
    • Target is a plant etc. (immobile, no XP)
    • Player Dex ≤ 0
    • Player is ^TSO and target is intelligent & not undead & not demonic
  2. Set Stab Tier (lower is better)
    • Tier 1: target is sleeping, paralyzed, or petrified
    • Tier 4: target is confused, distracted, cannot see you, petrifying, fleeing, friendly, caught in a net, caught in a web
  3. Check Tier 4 Stabs for Upgrade
    • If weapon is Spriggan’s Knife, upgrade to Tier 1.
    • If Potion of Stabbing is active, 50% chance to upgrade to Tier 1
  4. Check Tier 4 Stabs for Failure
    • Tier 1 stabs never fail
    • StabSkill = ½(WeaponSkill) + ½(StealthSkill)
    • (Dex + StabSkill + 1)% chance to succeed
  5. “Damage” is the damage rolled for the weapon
    • Adjusted for Strength roll, WeaponSkill roll, FightingSkill roll, Might/ Berserk roll, Slaying roll, Starvation Roll, Statue/Shadow Form Multiplier, Cleaving Multiplier, and Weak Status Multiplier, but before AC Reduction and Multiplicative Brands
  6. Apply Effects of a “Good Stab”
    • A “Good Stab” happens only if you are wielding a Short Blade, are a Felid, or are wearing the Hood of the Assassin
    1. Calculate an Additive Damage Bonus
      • The raw additive bonus is Dex*(StabSkill+100)
      • Divide this by 500 if the weapon is a dagger, by 1000 otherwise.
      • Apply a stepdown and cap of 30
      • Add this to Damage
    2. Calculate a Bonus Damage Multiplier
      • Bonus Multiplier is 1 + (StabSkill ÷ Tier ÷ 10)
      • Multiply Damage by this Bonus Multiplier
      • This multiplier is done before the one that all stabs get
  7. Calculate the Stabbing Damage Multiplier
    • Stabbing Multiplier is 1 + (StabSkill ÷ Tier ÷ 12)
    • Multiply Damage by the Stabbing Multiplier
Won (52). Remaining (15): 5 species: Ba, Fe, Mu, Na, Op; 5 Backgrounds: AM, Wr, Su, AE, Ar; 5 gods: Jiyv, newNem, WJC, newSif, newFedh

For this message the author MainiacJoe has received thanks:
petercordia

Return to Crazy Yiuf's Corner

Who is online

Users browsing this forum: No registered users and 20 guests

cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.