# Question about the game engine

**URL:** <https://discourse.cataclysmdda.org/t/question-about-the-game-engine/11734>\
**Category:** The Bunker\
**Created:** [April 20, 2016, 4:49pm UTC](https://discourse.cataclysmdda.org/t/question-about-the-game-engine/11734 "2016-04-20T16:49:47Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rama\_Tut](https://avatars.discourse-cdn.com/v4/letter/r/97f17d/32.png) [@Rama\_Tut](https://discourse.cataclysmdda.org/u/Rama_Tut)\
**Post date:** [April 20, 2016, 4:49pm UTC](https://discourse.cataclysmdda.org/t/question-about-the-game-engine/11734/1 "2016-04-20T16:49:47Z")

</div>

Someone was just commenting about the difficulty in getting zombies to hold their stuff so that when they revive, they’re not naked. Can someone who has seen the unpacked code tell me how CDDA is coded, in general terms? If I was coding a roguelike from scratch, I’d probably use object-oriented programming so I could create instances and move them inside of each other as virtual objects. It makes keeping track of what is where much easier in my experience. Does CDDA use a different style?

---

<div class="post-metadata">

**Author:** ![jcd](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/jcd/32/338_2.png) [@jcd](https://discourse.cataclysmdda.org/u/jcd)\
**Post date:** [April 20, 2016, 6:17pm UTC](https://discourse.cataclysmdda.org/t/question-about-the-game-engine/11734/2 "2016-04-20T18:17:13Z")

</div>

CDDA does that, but the codebase is quirky (arguably does what it has to do quite competently, but there are limitations)  
look [here](https://github.com/CleverRaven/Cataclysm-DDA/tree/master/src) for the whole codebase, and specifically the monster and mondeath files to undestand the problem. Revivification is handled by the MF\_REVIVES tag, so grep for this also.

IIRC items are only spawned on death, and are never part of a monster since a monster class differs from the NPC class in that it has no inventory (not the only difference). I don’t know if implementing all monsters as NPC’s (or even making a new monster class and then creating the NPC class as a subclass from that) is feasible.  
Best ask [here](http://smf.cataclysmdda.com/index.php?board=10.0) or raise an issue [here](https://github.com/CleverRaven/Cataclysm-DDA/issues) to get dev attention.

---

<div class="post-metadata">

**Author:** ![kevin.granade](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/kevin.granade/32/1316_2.png) [@kevin.granade](https://discourse.cataclysmdda.org/u/kevin.granade)\
**Post date:** [April 20, 2016, 6:41pm UTC](https://discourse.cataclysmdda.org/t/question-about-the-game-engine/11734/3 "2016-04-20T18:41:53Z")

</div>

Monsters do have an inventory, and we would be interested in doing drop spawn into that inventory at monster spawn time instead of at death.  
The real problem rhough is associating item drops with the corpse, the cirpse could “contain” them, but that would probably ne essitate changes elsewhere to keep item visibility working correctly.

---

<div class="post-metadata">

**Author:** ![MrQwerty](https://avatars.discourse-cdn.com/v4/letter/m/2acd7d/32.png) [@MrQwerty](https://discourse.cataclysmdda.org/u/MrQwerty)\
**Post date:** [April 20, 2016, 7:19pm UTC](https://discourse.cataclysmdda.org/t/question-about-the-game-engine/11734/4 "2016-04-20T19:19:27Z")

</div>

I just imagine my character looking in fear and disgust at all those naked zombies walking around xD

---

<div class="post-metadata">

**Author:** ![jcd](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/jcd/32/338_2.png) [@jcd](https://discourse.cataclysmdda.org/u/jcd)\
**Post date:** [April 20, 2016, 7:32pm UTC](https://discourse.cataclysmdda.org/t/question-about-the-game-engine/11734/5 "2016-04-20T19:32:23Z")

</div>

> [@Kevin Granade](#):
>
> The real problem rhough is associating item drops with the corpse, the cirpse could “contain” them, but that would probably necessitate changes elsewhere to keep item visibility working correctly.

Hmm, a ‘WORN\_BY’ tag for items could work maybe?  
When the corpse gets moved, the code could check if there are worn items by that corpse, and move them all together.  
At revive, the corpse should look for items ‘worn’ in the corpse tile and put them in the inventory.

Can’t remember if each zed has a specific id (i think not), but we’d have to somehow differentiate between each specific zed for this to work.

---

<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:** [April 20, 2016, 7:39pm UTC](https://discourse.cataclysmdda.org/t/question-about-the-game-engine/11734/6 "2016-04-20T19:39:52Z")

</div>

> [@jcd](#):
>
> Hmm, a ‘WORN\_BY’ tag for items could work maybe?

But then we’d need to handle tags on item creation to remove tags that shouldn’t be kept.  
For example, we’d need to prevent volume overload from putting all sorts of bras and panties on a nearby hulk corpse.

---

<div class="post-metadata">

**Author:** ![jcd](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/jcd/32/338_2.png) [@jcd](https://discourse.cataclysmdda.org/u/jcd)\
**Post date:** [April 20, 2016, 7:54pm UTC](https://discourse.cataclysmdda.org/t/question-about-the-game-engine/11734/7 "2016-04-20T19:54:33Z")

</div>

Right, no tag, it also cannot store info on who is wearing them.

On the same vein: A duplicate inventory for zeds? Invisible and not interacting with anything other than:  
At death it is not emptied, but stays intact.  
At move corpse it (a) updates itself removing all items it contains not on the source tile and (b) deletes them and respawns them on the target tile.  
At revification it also (a) updates and (b) deletes them from the ground and puts them in the ‘real’ inventory.

Its not that hacky i hope.

---

<div class="post-metadata">

**Author:** ![kevin.granade](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/kevin.granade/32/1316_2.png) [@kevin.granade](https://discourse.cataclysmdda.org/u/kevin.granade)\
**Post date:** [April 21, 2016, 1:54am UTC](https://discourse.cataclysmdda.org/t/question-about-the-game-engine/11734/8 "2016-04-21T01:54:19Z")

</div>

Monsters have an inventory, items have a contents array. What I meant is on death a monster can spawn a corpse and add items to it. You’d just need an update to code that displays items on the ground to also display those items. It might look just like it is now, or it might show that they are associated with a corpse. If the corpse revives the items would be added to the new mobsters inventory.

---

<div class="post-metadata">

**Author:** ![Rama\_Tut](https://avatars.discourse-cdn.com/v4/letter/r/97f17d/32.png) [@Rama\_Tut](https://discourse.cataclysmdda.org/u/Rama_Tut)\
**Post date:** [April 21, 2016, 2:46am UTC](https://discourse.cataclysmdda.org/t/question-about-the-game-engine/11734/9 "2016-04-21T02:46:56Z")

</div>

Maybe force players to “search corpse” to discover what it has, and use perception to allow for a potential bonus in finding better or more stuff.

---

<div class="post-metadata">

**Author:** ![kevin.granade](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/kevin.granade/32/1316_2.png) [@kevin.granade](https://discourse.cataclysmdda.org/u/kevin.granade)\
**Post date:** [April 21, 2016, 7:03am UTC](https://discourse.cataclysmdda.org/t/question-about-the-game-engine/11734/10 "2016-04-21T07:03:22Z")

</div>

It’d be more like a better check makes it faster, if you’re determined and take your tine you aren’t going to miss much on something the size of a corpse.
