# Martial Arts (and Melee/Dodge too) - How do they actually work, code-wise?

**URL:** <https://discourse.cataclysmdda.org/t/martial-arts-and-melee-dodge-too-how-do-they-actually-work-code-wise/7930>\
**Category:** The Bunker\
**Created:** [November 18, 2014, 3:22am UTC](https://discourse.cataclysmdda.org/t/martial-arts-and-melee-dodge-too-how-do-they-actually-work-code-wise/7930 "2014-11-18T03:22:30Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![AngryFrenchKanadian](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/angryfrenchkanadian/32/1078_2.png) [@AngryFrenchKanadian](https://discourse.cataclysmdda.org/u/AngryFrenchKanadian)\
**Post date:** [November 18, 2014, 3:22am UTC](https://discourse.cataclysmdda.org/t/martial-arts-and-melee-dodge-too-how-do-they-actually-work-code-wise/7930/1 "2014-11-18T03:22:30Z")

</div>

So I’ve been trying to figure out EXACTLY how Martial Arts work, especially now that you’re able to trigger some of them with melee weapons (other than with the melee weapon techniques).

The thing is, the wiki is being pretty vague with how melee attacks and melee blocks are triggered. I know that you need the proper melee level to access certain attacks and blocks but the wiki talk about stuff like: “If targeting a character with Grab break, checks the attacker’s (DEX + melee skill) 10 sided dice vs. the defender’s (DEX + melee skill) 12 sided dice for success.”

The way this is phrased is pretty counter-intuitive.

I also don’t understand how “crit” attacks are dertermined and how exactly the game determines which attack and block will be used.

I love this game but it has a lot of obscure calculations that lack context.

If someone could use an example by going through a whole scenario with pure character and monster stats and do some number crunching, it would be greatly appreciated.

Perhaps you could even start with how basic melee and dodge are calculated, because (3) melee and (2) dodge as stats don’t mean much to me without context.

---

<div class="post-metadata">

**Author:** ![Coolthulhu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/coolthulhu/32/2446_2.png) [@Coolthulhu](https://discourse.cataclysmdda.org/u/Coolthulhu)\
**Post date:** [November 18, 2014, 8:46am UTC](https://discourse.cataclysmdda.org/t/martial-arts-and-melee-dodge-too-how-do-they-actually-work-code-wise/7930/2 "2014-11-18T08:46:07Z")

</div>

Wiki is outdated on martial arts.

Martial arts attack techniques are quite straightforward: if you get a crit, only crit tecs are considered, otherwise non-crits. Then a random one is picked (equal weights). Some techniques have extra requirements to be considered, for example AoE attacks require more enemies around. Some martial arts techniques can be used with weapons (brawling’s power hit, for example), some weapons have their techniques.  
Some martial arts are fully compatible with weapons (all techs will work) and unarmed weapons are also compatible with all martial arts.

Technique levels on wiki are outdated, you’ll need to check out jsons:

> <https://github.com/CleverRaven/Cataclysm-DDA/blob/master/data/json/techniques.json>

  

> <https://github.com/CleverRaven/Cataclysm-DDA/blob/master/data/json/martialarts.json>

  
They work like this: a martial art has a list of techniques, a list of buffs (if any), an arm block level and leg block level. Two first seem straightforward to me, arm and leg block are levels when this type of block is unlocked. I think -1 doesn’t mean “never”, but “always”.

Crits result from high accuracy and are rolled separately from regular attack to-hit. Calculation is quite complex and I suggest reading the source:

> <https://github.com/CleverRaven/Cataclysm-DDA/blob/master/src/melee.cpp>

  
You can expect to melee crit all the time later in game, unless you burden your torso heavily.

EDIT: Not sure where is the part below used. Not in ability dodges at least.  
Dodge roll involves rolling dice(dodge\_stat, 10) vs. hit accuracy.  
You can dodge only once per turn, unless something allows more. Those extra dodges are penalized (check out melee.cpp I linked above).

EDIT: This one is for special abilities, like smash. It’s not limited by number of dodges.  
Dodge\_stat (for player) is dex/2 + dodge\_skill - torso encumbrance (+/- other effects).  
Now subtract a random number from 0 to monster’s melee\_skill (a flat number, read up monsters.json for exact values) and cap at 0 so that it doesn’t get negative. Name this number dodge\_check.  
Then if random number from 0 to 10000 is lower than 10000 / (1 + 99 \* exp(-0.6 \* dodge\_check) ), you dodge. Otherwise you don’t. Monsters don’t crit (I think).  
The formula above looks intimidating, but if you plug it in [wolframalpha.com](http://wolframalpha.com) (with dodge\_check replaced by n), it gives you a nice table somewhere below on the page.  
EDIT: Monsters have dodge rolls, so they probably can dodge something. They certainly can use it make crits less likely, and avoid AoE techniques, but can’t find anything else a monster could dodge.

As for example (of dodge roll - it’s simpler) - brute with melee skill 4 tries to SMASH an 8 dex, 5 dodge survivor with 1 torso encumbrance. Survivor’s dodge is 8/2+5-1=9.  
Brute gets a 3 on its melee rng(0, melee\_skill), so dodge\_check is 6. Now look up the formula: 10000 / (1 + 99 \* exp(-0.6 \* 6) ) = 2699. Chance for rng(0, 100000) to be smaller than 2699 is 2699/1000=27%.

---

<div class="post-metadata">

**Author:** ![AngryFrenchKanadian](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/angryfrenchkanadian/32/1078_2.png) [@AngryFrenchKanadian](https://discourse.cataclysmdda.org/u/AngryFrenchKanadian)\
**Post date:** [November 18, 2014, 11:55pm UTC](https://discourse.cataclysmdda.org/t/martial-arts-and-melee-dodge-too-how-do-they-actually-work-code-wise/7930/3 "2014-11-18T23:55:34Z")

</div>

Thanks for the infodump. Sometimes I just wonder how a certain mechanic in the game functions. I appreciate you taking the time to write this little guide and for diving a bit in the code.

---

<div class="post-metadata">

**Author:** ![KA101](https://avatars.discourse-cdn.com/v4/letter/k/278dde/32.png) [@KA101](https://discourse.cataclysmdda.org/u/KA101)\
**Post date:** [November 19, 2014, 12:45am UTC](https://discourse.cataclysmdda.org/t/martial-arts-and-melee-dodge-too-how-do-they-actually-work-code-wise/7930/4 "2014-11-19T00:45:31Z")

</div>

It’d look well in the wiki. 😉

---

<div class="post-metadata">

**Author:** ![AngryFrenchKanadian](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/angryfrenchkanadian/32/1078_2.png) [@AngryFrenchKanadian](https://discourse.cataclysmdda.org/u/AngryFrenchKanadian)\
**Post date:** [November 19, 2014, 8:07am UTC](https://discourse.cataclysmdda.org/t/martial-arts-and-melee-dodge-too-how-do-they-actually-work-code-wise/7930/5 "2014-11-19T08:07:15Z")

</div>

Yeah, the wiki is in major need of some revamping.

If I had some more free time I’d probably do something about it but I barely got the time to even play Cataclysm.

---

<div class="post-metadata">

**Author:** ![Coolthulhu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/coolthulhu/32/2446_2.png) [@Coolthulhu](https://discourse.cataclysmdda.org/u/Coolthulhu)\
**Post date:** [November 19, 2014, 9:29am UTC](https://discourse.cataclysmdda.org/t/martial-arts-and-melee-dodge-too-how-do-they-actually-work-code-wise/7930/6 "2014-11-19T09:29:09Z")

</div>

EDIT: Wanted to edit, quoted instead.  
Anyway, I re-read some of those formulas to make sure. Apparently I was wrong about some of them. Updated the big post.

---

<div class="post-metadata">

**Author:** ![AngryFrenchKanadian](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/angryfrenchkanadian/32/1078_2.png) [@AngryFrenchKanadian](https://discourse.cataclysmdda.org/u/AngryFrenchKanadian)\
**Post date:** [November 20, 2014, 4:01am UTC](https://discourse.cataclysmdda.org/t/martial-arts-and-melee-dodge-too-how-do-they-actually-work-code-wise/7930/7 "2014-11-20T04:01:13Z")

</div>

[quote=“Coolthulhu, post:6, topic:7930”]EDIT: Wanted to edit, quoted instead.  
Anyway, I re-read some of those formulas to make sure. Apparently I was wrong about some of them. Updated the big post.[/quote]

Ah, thanks again for going the extra mile!
