# Code for butchering

**URL:** https://discourse.cataclysmdda.org/t/code-for-butchering/7692
**Category:** The Toolbox
**Created:** [October 28, 2014, 10:13am UTC](https://discourse.cataclysmdda.org/t/code-for-butchering/7692 "2014-10-28T10:13:57Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Snaaty](https://avatars.discourse-cdn.com/v4/letter/s/e495f1/32.png) [@Snaaty](https://discourse.cataclysmdda.org/u/Snaaty)
#### Post date: [October 28, 2014, 10:13am UTC](https://discourse.cataclysmdda.org/t/code-for-butchering/7692/1 "2014-10-28T10:13:57Z")

</div>

Hi,

so, I am trying to figure out the butchering code in order to eventually add more butchering products.

`if (fats > 0) {
        if (corpse->has_flag(MF_FAT)) {
            m.spawn_item(u.posx, u.posy, "fat", fats, 0, age);
            add_msg(m_good, _("You harvest some fat!"));
        }`

This is the code in game.cpp, that handles fat being spawned after butchery. My question here is now, do I have to define the flag “MF\_FAT” somewhere? Or is it automatically done for the corpse, as long as I give the monster in its json the flag “FAT”?

I might have more consecutive questions, but please answer me this one first, if possible.

---

<div class="post-metadata">

### Author: ![BevapDin](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/bevapdin/32/228_2.png) [@BevapDin](https://discourse.cataclysmdda.org/u/BevapDin)
#### Post date: [October 28, 2014, 1:20pm UTC](https://discourse.cataclysmdda.org/t/code-for-butchering/7692/2 "2014-10-28T13:20:37Z")

</div>

> do I have to define the flag "MF\_FAT" somewhere?

It is already defined somewhere, otherwise the compiler would complain.

Have you looked up what [tt]corpse[/tt] is and where it comes from? Just in case, it’s a pointer to a monster type ([tt]mtype[/tt]), which is loaded from json, see monstergenerator.cpp - it also contains the logic to load those flags from json.

> Or is it automatically done for the corpse, as long as I give the monster in its json the flag "FAT"?

As long as there is a translation entry in [tt]flag\_map[/tt] (which translates the flag [i]string[/i] (from json) into the C++ [i]enumeration value[/i]), the flag will be loaded from the json and [b]added[/b] to the monster type definition. Than it's also present in the butchering code.

And in case you want to add a new flag, you have to define it in mtype.h and you have to add an entry in the [tt]flag\_map[/tt].

---

<div class="post-metadata">

### Author: ![Snaaty](https://avatars.discourse-cdn.com/v4/letter/s/e495f1/32.png) [@Snaaty](https://discourse.cataclysmdda.org/u/Snaaty)
#### Post date: [October 28, 2014, 10:27pm UTC](https://discourse.cataclysmdda.org/t/code-for-butchering/7692/3 "2014-10-28T22:27:09Z")

</div>

Ah, BevapDin, you’re the best!

I couldn’t figure out that monstergenerator.cpp was the thing I was looking for.

Now, for further work, if I wanted to add a hypothetical flag [“TAINTED\_BUTCHER”] for zombies to drop "tainted bones"and “tainted fat”, I’d have to give the zombies in their jsons the “TAINTED\_BUTCHER” flag, add the “translation” to monstergenerator.cpp (?)and then also define the “MF\_TAINTED\_BUTCHER” in the mtype.h.
