Skip to content

Commit

Permalink
Merge remote-tracking branch 'DFHack/dfhack/develop' into migrate_nes…
Browse files Browse the repository at this point in the history
…tboxes_to_autobutcher
  • Loading branch information
Birkow committed Sep 28, 2024
2 parents b014ec6 + ca01706 commit eef2928
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 35 deletions.
95 changes: 61 additions & 34 deletions data/blueprints/aquifer_tap.csv
Original file line number Diff line number Diff line change
Expand Up @@ -7,52 +7,79 @@ Here's the procedure:
""
2) Dig a one-tile-wide tunnel from where you want the water to end up (e.g. your well cistern) to an area on the same z-level directly below the target light aquifer. Dig a one-tile-wide diagonal segment in this tunnel near the cistern side so water that will eventually flow through the tunnel is depressurized.
""
"3) From the end of that tunnel, go down one z-level, enable damp dig mode in the dig toolbar, then dig a staircase straight up so that the top is in the lowest aquifer level (a tile with a two-drop icon). Change the top staircase tile (the down-only stairs) to a ""blueprint"" tile (default hotkey: m-L) so your miners don't dig it yet."
"3) Pause the game. From the end of that tunnel, go down one z-level, enable damp dig mode in the dig toolbar, then designate for digging a staircase straight up so that the top is in the lowest aquifer level (a tile with a two-drop icon). If you only have one layer of aquifer, you should end the staircase one level below the aquifer so when we dig the tap, it will extend up into the aquifer level. Your tunnel should connect to the staircase one z-level above the bottom of the staircase."
""
"4) From the bottom of the staircase (the z-level below where the water will flow to your cisterns), dig a straight, one-tile wide tunnel to the closest edge of the map. This is your emergency drainage tunnel. Smooth the map edge tile and carve a fortification. The water can flow through the fortification and off the map, allowing the dwarves to dig out the aquifer tap without drowning."
"4) Apply this blueprint (gui/quickfort aquifer_tap /dig) to the z-level at the top of the staircase. The tiles will be designated in ""damp dig"" mode so your miners can dig it out without the damp tiles canceling the digging designations. This blueprint designates ramps for digging so two layers of aquifer can contribute to the water collector. It also changes the staircase tile below the tap to a ""blueprint"" tile so your miners don't dig the tap before your drainage tunnel is ready."
""
5) Place a lever-controlled floodgate in the drainage tunnel and open the floodgate. Place the lever somewhere else in your fort so that it will remain dry and accessible.
"5) You can now unpause the game. From the bottom of the staircase (the z-level below where the water will flow to your cisterns), dig a straight, one-tile wide tunnel to the closest edge of the map. This is your emergency drainage tunnel. Smooth the map edge tile and carve a fortification. The water can flow through the fortification and off the map, allowing the dwarves to dig out the aquifer tap without drowning."
""
"6) If you want, haul away any boulders in the tunnels and/or smooth the tiles (e.g. mark them for dumping -- hotkey i-p -- and wait for them to be dumped). You won't be able to access any of this area once it fills up with water!"
6) Place a lever-controlled floodgate in the drainage tunnel and open the floodgate. Place the lever somewhere else in your fort so that it will remain dry and accessible.
""
"7) Apply this blueprint (gui/quickfort aquifer_tap /dig) to the z-level above the top of the staircase, inside the lowest aquifer level. The tiles will be designated in ""damp dig"" mode so your miners can dig it out without the damp tiles canceling the digging designations. This blueprint designates ramps for digging so two layers of aquifer can contribute to the water collector."
"7) If you want, haul away any boulders in the tunnels and/or smooth the tiles (e.g. mark them for dumping -- hotkey i-p -- and wait for them to be dumped). Enable prioritize in gui/control-panel to focus dwarves on dumping tasks and make it go faster. You won't be able to access any of this area once it fills up with water!"
""
"8) Dig out the tap. You can haul away any boulders and remove the ramps if you like. The water will safely flow down the staircase, through the open floodgate, down the drainage tunnel, and off the map as long as the floodgate is open."
"8) Convert the ""blueprint"" stairway tile to a regular up/down stair dig designation to allow your miners to dig out the tap. You can haul away any boulders and remove the ramps if you like. There is no rush. The water will safely flow down the staircase, through the open floodgate, down the drainage tunnel, and off the map as long as the floodgate is open."
"8b) Sometimes, DF gets into a bad state with mining designations and miners will refuse to dig the stairway tile. If this happens to you, enter mining mode, enable the keyboard cursor if it's not already enabled (hotkey: Alt-k), highlight the undug stair designation, and run dig-now here in gui/launcher. You might also have to do this for the down stair designation in the center of the aquifer tap. Your miners should be able to handle the rest without assistance."

"9) Once everything is dug out and all dwarves are out of the waterways, close the floodgate. Your cisterns will fill with water. Since the waterway to your cisterns is depressurized, the cisterns will stay forever full, but will not flood."
"9) Once everything is dug out and all dwarves are out of the waterways, close the floodgate. Your cisterns will fill with water. Since the waterway to your cisterns is depressurized (due to the diagonal tunnel you dug), the cisterns will stay forever full, but will not flood."
""
A diagram might be useful. Here is a vertical view through the z-levels. This blueprint goes at the top:
""
"j <- down stairs, center of this blueprint"
i
"j <- down stairs, center of this blueprint"
"i <- up/down stairs, initially in ""blueprint mode"" to prevent digging before drainage is ready"
"... <- up/down stairs, make this as tall as you need"
i
i <- cistern outlet level
i <- cistern outlet level with diagonal tunnel to depressurize
"u <- up stairs, drainage level"
""
"Good luck! If done right, this method is the safest way to supply your fort with clean water."
#dig label(dig) start(13 13 center of tap) light aquifer water collector

,,,,,,,,,,,,mdr
,,,,,,,,,,,,mdr
,,,,,mdr,mdr,mdr,mdr,mdr,mdr,mdr,mdr,mdr,mdr,mdr,mdr,mdr,mdr,mdr
,,,,,,,,,,,,mdr
,,,mdr,,,,,,,,,mdr,,,,,,,,,mdr
,,,mdr,,,,,mdr,mdr,mdr,mdr,mdr,mdr,mdr,mdr,mdr,,,,,mdr
,,,mdr,,,,,,,,,mdr,,,,,,,,,mdr
,,,mdr,,,mdr,,,,,,mdr,,,,,,mdr,,,mdr
,,,mdr,,,mdr,,,,,mdr,mdr,mdr,,,,,mdr,,,mdr
,,,mdr,,,mdr,,,,,,mdr,,,,,,mdr,,,mdr
,,,mdr,,,mdr,,,mdr,,,mdr,,,mdr,,,mdr,,,mdr
,mdr,mdr,mdr,mdr,mdr,mdr,mdr,mdr,mdr,mdr,mdr,mdj,mdr,mdr,mdr,mdr,mdr,mdr,mdr,mdr,mdr,mdr,mdr
,,,mdr,,,mdr,,,mdr,,,mdr,,,mdr,,,mdr,,,mdr
,,,mdr,,,mdr,,,,,,mdr,,,,,,mdr,,,mdr
,,,mdr,,,mdr,,,,,mdr,mdr,mdr,,,,,mdr,,,mdr
,,,mdr,,,mdr,,,,,,mdr,,,,,,mdr,,,mdr
,,,mdr,,,,,,,,,mdr,,,,,,,,,mdr
,,,mdr,,,,,mdr,mdr,mdr,mdr,mdr,mdr,mdr,mdr,mdr,,,,,mdr
,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,,,,
,,,,,,,,,,,,`,,,,,,,,,,,,
,,,,,,,,,,,,`,,,,,,,,,,,,
3 changes: 3 additions & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,16 @@ Template for new versions:
## New Tools

## New Features
- `tweak`: ``realistic-melting``: change melting return for inorganic armor parts, shields, weapons, trap components and tools to stop smelters from creating metal, bring melt return for adamantine in line with other metals to ~95% of forging cost. wear reduces melt return by 10% per level

## Fixes

## Misc Improvements
- DFHack text edit fields now delete the character at the cursor when you hit the Delete key
- DFHack text edit fields now move the cursor by one word left or right with Ctrl-Left and Ctrl-Right
- DFHack text edit fields now move the cursor to the beginning or end of the line with Home and End
- Quickfort blueprint library: ``aquifer_tap`` blueprint walkthough rewritten for clarity
- Quickfort blueprint library: ``aquifer_tap`` blueprint now designated at priority 3 and marks the stairway tile below the tap in "blueprint" mode to prevent drips while the drainage pipe is being prepared
- `preserve-rooms`: automatically release room reservations for captured squad members. we were kidding ourselves with our optimistic kept reservations. they're unlikely to come back : ((
- `autobutcher`: added nestboxes lua script giving more control how fertile eggs should be protected, with possibility to adjust configuration per race

Expand Down
2 changes: 2 additions & 0 deletions docs/plugins/dwarfvet.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ unassigned from the pasture while in treatment. The animal will be reassigned
to its original pasture shortly after recovery.

Animals that are on restraints or in cages will not be designated for treatment.
Animals require an empty tile of floor to rest on while recovering, so your
hospital must have some unoccupied floor space in order for animals to use it.

You can enable ``dwarfvet`` in `gui/control-panel`, and you can choose to start
``dwarfvet`` automatically in new forts in the ``Gameplay`` -> ``Autostart``
Expand Down
13 changes: 13 additions & 0 deletions docs/plugins/tweak.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ Commands
Names filled waterskins, flasks, and vials according to their contents,
the same way other containers such as barrels, bins, and cages are named.
(:bug:`4914`)
``realistic-melting``
Makes amortized metal bar returns for melting uniform across all item types.
Affects weapons, shields, armor parts, tools, and trap components. The target
amount of metal produced by melting is 95% of the metal used for production
of the item. Each level of wear decreases melt return by a further 10%. The game
has a fixed granularity of 0.3 for metal bar returns, so individual items will
randomly return an amount that may be above or below the target. For example
a metal cap with item size 1 will produce 0.9 of a bar with a 16.6% chance of
producing an additional 0.3 of a bar. Over time, the average return for melting
these types of caps will be ~0.95 of a bar. Calculations for melting return are
done for items with base game production cost. Melting return might not be
calculated correctly for modded items or items created in custom reactions
that don't respect vanilla production costs. (:bug:`6027`)
``named-codices``
Displays titles for books instead of the default material description.
``partial-items``
Expand Down
10 changes: 10 additions & 0 deletions plugins/tweak/tweak.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ using namespace DFHack;
#include "tweaks/eggs-fertile.h"
#include "tweaks/fast-heat.h"
#include "tweaks/flask-contents.h"
#include "tweaks/material-size-for-melting.h"
#include "tweaks/named-codices.h"
#include "tweaks/partial-items.h"
#include "tweaks/reaction-gloves.h"
Expand Down Expand Up @@ -74,6 +75,15 @@ DFhackCExport command_result plugin_init(color_ostream &out, vector<PluginComman

TWEAK_HOOK("reaction-gloves", reaction_gloves_hook, produce);

TWEAK_HOOK("realistic-melting", material_size_for_melting_armor_hook, getMaterialSizeForMelting);
TWEAK_HOOK("realistic-melting", material_size_for_melting_gloves_hook, getMaterialSizeForMelting);
TWEAK_HOOK("realistic-melting", material_size_for_melting_shoes_hook, getMaterialSizeForMelting);
TWEAK_HOOK("realistic-melting", material_size_for_melting_helm_hook, getMaterialSizeForMelting);
TWEAK_HOOK("realistic-melting", material_size_for_melting_pants_hook, getMaterialSizeForMelting);
TWEAK_HOOK("realistic-melting", material_size_for_melting_weapon_hook, getMaterialSizeForMelting);
TWEAK_HOOK("realistic-melting", material_size_for_melting_trapcomp_hook, getMaterialSizeForMelting);
TWEAK_HOOK("realistic-melting", material_size_for_melting_tool_hook, getMaterialSizeForMelting);

return CR_OK;
}

Expand Down
69 changes: 69 additions & 0 deletions plugins/tweak/tweaks/material-size-for-melting.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#include <cmath>

#include "modules/Materials.h"
#include "modules/Random.h"

#include "df/inorganic_raw.h"
#include "df/item_armorst.h"
#include "df/item_constructed.h"
#include "df/item_glovesst.h"
#include "df/item_helmst.h"
#include "df/item_pantsst.h"
#include "df/item_shieldst.h"
#include "df/item_shoesst.h"
#include "df/item_toolst.h"
#include "df/item_trapcompst.h"
#include "df/item_weaponst.h"

struct Mrng {
Random::MersenneRNG rng;
Mrng() { rng.init(); }
};

static float get_random() {
static Mrng mrng;
return static_cast <float> (mrng.rng.drandom1());
}

static int32_t get_material_size_for_melting(df::item_constructed *item, int32_t base_material_size, float production_stack_size) {
const float melt_return_per_material_size = 0.3f, base_melt_recovery = 0.95f, loss_per_wear_level = 0.1f;

if (item->mat_type != 0) // bail if not INORGANIC
return base_material_size;

float forging_cost_per_item;
if (auto inorganic = df::inorganic_raw::find(item->mat_index);
inorganic && inorganic->flags.is_set(df::inorganic_flags::DEEP_SPECIAL))
{
// adamantine items
forging_cost_per_item = static_cast<float>(base_material_size) / production_stack_size;
} else {
// non adamantine items
forging_cost_per_item = std::max(std::floor(static_cast<float>(base_material_size) / 3.0f), 1.0f);
forging_cost_per_item /= production_stack_size;
}

float calculated_size = forging_cost_per_item / melt_return_per_material_size;
float melt_recovery = base_melt_recovery - static_cast<float>(item->wear) * loss_per_wear_level;
calculated_size *= melt_recovery;
int32_t random_part = ((modff(calculated_size, &calculated_size) > get_random()) ? 1 : 0);
return static_cast<int32_t>(calculated_size) + random_part;
}

#define DEFINE_MATERIAL_SIZE_FOR_MELTING_TWEAK(TYPE, PRODUCTION_STACK_SIZE) \
struct material_size_for_melting_##TYPE##_hook : df::item_##TYPE##st {\
typedef df::item_##TYPE##st interpose_base;\
DEFINE_VMETHOD_INTERPOSE(int32_t, getMaterialSizeForMelting, ()) {\
return get_material_size_for_melting(this, INTERPOSE_NEXT(getMaterialSizeForMelting)(), PRODUCTION_STACK_SIZE);\
}\
};\
IMPLEMENT_VMETHOD_INTERPOSE(material_size_for_melting_##TYPE##_hook, getMaterialSizeForMelting);

DEFINE_MATERIAL_SIZE_FOR_MELTING_TWEAK(armor, 1.0f)
DEFINE_MATERIAL_SIZE_FOR_MELTING_TWEAK(gloves, 2.0f)
DEFINE_MATERIAL_SIZE_FOR_MELTING_TWEAK(shoes, 2.0f)
DEFINE_MATERIAL_SIZE_FOR_MELTING_TWEAK(helm, 1.0f)
DEFINE_MATERIAL_SIZE_FOR_MELTING_TWEAK(pants, 1.0f)
DEFINE_MATERIAL_SIZE_FOR_MELTING_TWEAK(weapon, 1.0f)
DEFINE_MATERIAL_SIZE_FOR_MELTING_TWEAK(trapcomp, 1.0f)
DEFINE_MATERIAL_SIZE_FOR_MELTING_TWEAK(tool, 1.0f)

0 comments on commit eef2928

Please sign in to comment.