Hey fabulous modders! I know that myself, like many people, have been bothered by the clutter that invading forces bring. Ammunition, socks, cotton pants, bits of armour; clutter management isn't enjoyable, and yet it takes a lot of my in-game effort.
However what also bothers me is that material from invaders can make the game too easy, at least in the mods I enjoy. Goblinite might be fine, but if you're playing Masterwork, and mithril-clad elves mount an ambush (which they do all the time if you're playing orcs), then suddenly you have a bunch of mithril, which should be rare and hard to come by.
I hope to have a way that efficiently solves both of these problems with the help of DFHack, and I'm hoping for your feedback.
Put simply, we introduce a way of saying that a material or item is 'volatile'. If it's being carried or worn, then nothing happens, but if it's dropped then it's converted to another, non-volatile material. This would allow elves to arrive with 'enchanted mithril armour', which reverts back to wooden armour when dropped. Or goblins could arrive with 'worn cotton pants', which revert to a material with a low boiling point when dropped (causing them to evaporate). This opens the way for both low-clutter invasions, and invaders with high-level materials but without players ending up with a glut of those same materials.
From a coding standpoint, it should be possible to do this very efficiently using a mark and sweep arrangement. Here's some psuedocode:
// Mark - Start by examining all our units and recording volatile items in their
// inventory. We only ever have to examine a unit once, since volatile items
// will only be held by invaders, and can never be acquired except through
// unit generation.
foreach (unit <- all_units)
next if unit_already_seen()
foreach (item <- unit.inventory)
next if not item.volatile
volatile_list.add(item)
// Sweep (this can be a separate DFHack thread)
foreach (item <- volatile_list)
if (item.not_held or item.not_held_by_original_owner)
item.convert_material()
As for the volatile materials themselves, I'd propose the material have a 'VOLATILE_(identifier)_BECOMES_(new material)' naming convention. For example: 'VOLATILE_MITHRIL_BECOMES_WOOD' (converts to INORGANIC:WOOD on dropping), or 'VOLATILE_WORN_COTTON_BECOMES_SMOKE' (INORGANIC:SMOKE can be a custom material with a low boiling point). The use of the 'BECOMES' component over a 'VOLATILE_IDENTIFIER_NEWMAT' syntax is that additional underscores can be used on both sides, preserving clarity. This should work great for inorganics, and my understanding is that DF is pretty tolerant of an item's material being changed via DFHack. I'm not yet familiar with how organics (which I presume includes leather) work in DF, so guidance here is appreciated.
I will admit that while I have a lifetime of experience with software engineering, I'm still finding my way with DFHack. So if you see any potential pitfalls, are aware of any similar scripts that have been written, or even wish to write this script yourself, I would be delighted.
Thank you very much for your time!
~ T