Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: [DFHack] RFC: Reducing clutter with volatile items  (Read 1198 times)

Urist McTeellox

  • Bay Watcher
    • View Profile
[DFHack] RFC: Reducing clutter with volatile items
« on: December 25, 2013, 10:12:26 pm »

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:

Code: [Select]

// 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
Logged

Urist McTeellox

  • Bay Watcher
    • View Profile
Re: [DFHack] RFC: Reducing clutter with volatile items
« Reply #1 on: January 09, 2014, 10:41:26 pm »

Just making a note to myself that we should check to see that the enemy flag is set on the unit before marking their item as volatile. Otherwise if you're playing a race that might show up as an enemy for someone else (eg, in Masterwork) then your trader's materials may evaporate upon unpacking, or other oddness.

~ T
Logged

Quietust

  • Bay Watcher
  • Does not suffer fools gladly
    • View Profile
    • QMT Productions
Re: [DFHack] RFC: Reducing clutter with volatile items
« Reply #2 on: January 10, 2014, 10:37:59 am »

There's actually a much simpler way of doing this - since dropping an item on the ground is done using a virtual method call (known in DFHack by the signature "virtual bool itemst::moveToGround(int16_t x, int16_t y, int16_t z);"), you can simply interpose that vmethod for the desired item types (in a C++ plugin) and do all of the logic in there. Placing the item in a building (whether a workshop or a trade depot) would not trigger it, nor would storing it inside a stockpile container (though storing it on a stockpile floor tile would trigger it), so you could still use this sort of behavior with items produced by your own dwarves or acquired through trading.

There's also no need to use a special naming convention  - just add [MATERIAL_REACTION_PRODUCT:DROP_ON_FLOOR:new_material] and look for that in the 'degrade' logic.
« Last Edit: January 10, 2014, 10:42:35 am by Quietust »
Logged
P.S. If you don't get this note, let me know and I'll write you another.
It's amazing how dwarves can make a stack of bones completely waterproof and magmaproof.
It's amazing how they can make an entire floodgate out of the bones of 2 cats.

Urist McTeellox

  • Bay Watcher
    • View Profile
Re: [DFHack] RFC: Reducing clutter with volatile items
« Reply #3 on: January 10, 2014, 11:20:53 am »

There's actually a much simpler way of doing this - since dropping an item on the ground is done using a virtual method call (known in DFHack by the signature "virtual bool itemst::moveToGround(int16_t x, int16_t y, int16_t z);"), you can simply interpose that vmethod for the desired item types (in a C++ plugin) and do all of the logic in there. Placing the item in a building (whether a workshop or a trade depot) would not trigger it, nor would storing it inside a stockpile container (though storing it on a stockpile floor tile would trigger it), so you could still use this sort of behavior with items produced by your own dwarves or acquired through trading.

Neat! This does present a bit of a gotcha for me personally. I'm running Linux, and run (and contribute to) Masterwork for Windows (which I run under wine).  Is there a way to cross-compile DFHack plug-ins for Windows, even though I'm running Linux natively?

Quote
There's also no need to use a special naming convention  - just add [MATERIAL_REACTION_PRODUCT:DROP_ON_FLOOR:new_material] and look for that in the 'degrade' logic.

This is brilliant, and definitely the way to go! Thank you! :)

~ T
Logged

Quietust

  • Bay Watcher
  • Does not suffer fools gladly
    • View Profile
    • QMT Productions
Re: [DFHack] RFC: Reducing clutter with volatile items
« Reply #4 on: January 10, 2014, 11:25:07 am »

Is there a way to cross-compile DFHack plug-ins for Windows, even though I'm running Linux natively?
Yes - run Microsoft Visual C++ 2010 under Wine (assuming it works).
Logged
P.S. If you don't get this note, let me know and I'll write you another.
It's amazing how dwarves can make a stack of bones completely waterproof and magmaproof.
It's amazing how they can make an entire floodgate out of the bones of 2 cats.

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Re: [DFHack] RFC: Reducing clutter with volatile items
« Reply #5 on: May 28, 2014, 07:36:24 am »

*Meph castes thread-necromancy lvl15.
*The thread shudders and comes to life.

Any coders wants to finish that idea? It would allow fully armored and fancy magical invaders, which do not leave any clutter and do not hurt FPS in any way. :)
Logged
::: ☼Meph Tileset☼☼Map Tileset☼- 32x graphic sets with TWBT :::
::: ☼MASTERWORK DF☼ - A comprehensive mod pack now on Patreon - 250.000+ downloads and counting :::
::: WorldBicyclist.com - Follow my bike tours around the world - 148 countries visited :::

Warmist

  • Bay Watcher
  • Master of unfinished jobs
    • View Profile
Re: [DFHack] RFC: Reducing clutter with volatile items
« Reply #6 on: May 28, 2014, 08:46:03 am »

*Meph castes thread-necromancy lvl15.
*The thread shudders and comes to life.

Any coders wants to finish that idea? It would allow fully armored and fancy magical invaders, which do not leave any clutter and do not hurt FPS in any way. :)
I might do something. I was toying with idea of new mechanics based on this. Namely: anti-quantum stockpile, automatic manufacture (with minecarts and special workshops), mass smelting with lava (would require some ingenuity on players part to make it work). Though not sure how much time i'll have (and also i need to finish all the other projects  :P )
EDIT: [MATERIAL_REACTION_PRODUCT:DROP_ON_FLOOR:new_material] is done, though to really remove maybe some other way is needed... though i also exposed it to lua so it might be easier to make a script that does that...
« Last Edit: May 28, 2014, 11:23:28 am by Warmist »
Logged