From a7998f71a2ee95d2d21f34468761118fd6b8585f Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Tue, 18 Sep 2012 17:39:37 +0400 Subject: [PATCH] Add a tweak workaround for the issue with container reactions in advmode. --- NEWS | 2 + dfhack.init-example | 4 ++ plugins/raw/reaction_spatter.txt | 2 +- plugins/tweak.cpp | 71 ++++++++++++++++++++++++++++++++ 4 files changed, 78 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 68551d385..22f64d7d6 100644 --- a/NEWS +++ b/NEWS @@ -25,6 +25,8 @@ DFHack v0.34.11-r2 (UNRELEASED) - tweak readable-build-plate: fix unreadable truncation in unit pressure plate build ui. - tweak stable-temp: fixes bug 6012; may improve FPS by 50-100% on a slow item-heavy fort. - tweak fast-heat: speeds up item heating & cooling, thus making stable-temp act faster. + - tweak fix-dimensions: fixes subtracting small amounts from stacked liquids etc. + - tweak advmode-contained: fixes UI bug in custom reactions with container inputs in advmode. New scripts: - fixnaked: removes thoughts about nakedness. - setfps: set FPS cap at runtime, in case you want slow motion or speed-up. diff --git a/dfhack.init-example b/dfhack.init-example index b8b53cad7..83c3641b6 100644 --- a/dfhack.init-example +++ b/dfhack.init-example @@ -86,3 +86,7 @@ tweak fast-heat 500 # stop stacked liquid/bar/thread/cloth items from lasting forever # if used in reactions that use only a fraction of the dimension. tweak fix-dimensions + +# make reactions requiring containers usable in advmode - the issue is +# that the screen asks for those reagents to be selected directly +tweak advmode-contained diff --git a/plugins/raw/reaction_spatter.txt b/plugins/raw/reaction_spatter.txt index 229e531c8..085be7fdd 100644 --- a/plugins/raw/reaction_spatter.txt +++ b/plugins/raw/reaction_spatter.txt @@ -21,7 +21,7 @@ Reaction name must start with 'SPATTER_ADD_': [REAGENT:grease:1:GLOB:NONE:NONE:NONE][REACTION_CLASS:FAT][UNROTTEN] The probability is used as spatter size; Legendary gives +90%: COVERED = liquid, GLAZED = solid, BANDS = paste, SPIKES = powder - [IMPROVEMENT:800:object:BANDS:GET_MATERIAL_FROM_REAGENT:extract:NONE] + [IMPROVEMENT:800:object:COVERED:GET_MATERIAL_FROM_REAGENT:extract:NONE] [REACTION:SPATTER_ADD_WEAPON_EXTRACT] [NAME:coat weapon with extract] diff --git a/plugins/tweak.cpp b/plugins/tweak.cpp index 4fef285f9..fb286e0d7 100644 --- a/plugins/tweak.cpp +++ b/plugins/tweak.cpp @@ -29,6 +29,7 @@ #include "df/criminal_case.h" #include "df/unit_inventory_item.h" #include "df/viewscreen_dwarfmodest.h" +#include "df/viewscreen_layer_unit_actionst.h" #include "df/squad_order_trainst.h" #include "df/ui_build_selector.h" #include "df/building_trapst.h" @@ -38,6 +39,10 @@ #include "df/item_threadst.h" #include "df/item_clothst.h" #include "df/contaminant.h" +#include "df/layer_object.h" +#include "df/reaction.h" +#include "df/reaction_reagent_itemst.h" +#include "df/reaction_reagent_flags.h" #include @@ -100,6 +105,10 @@ DFhackCExport command_result plugin_init (color_ostream &out, std::vector *input)) + { + auto old_reaction = cur_reaction; + auto old_reagent = reagent; + + INTERPOSE_NEXT(feed)(input); + + if (cur_reaction && (cur_reaction != old_reaction || reagent != old_reagent)) + { + old_reagent = reagent; + + // Skip reagents already contained by others + while (reagent < (int)cur_reaction->reagents.size()-1) + { + if (!cur_reaction->reagents[reagent]->flags.bits.IN_CONTAINER) + break; + reagent++; + } + + if (old_reagent != reagent) + { + // Reproduces a tiny part of the orginal screen code + choice_items.clear(); + + auto preagent = cur_reaction->reagents[reagent]; + reagent_amnt_left = preagent->quantity; + + for (int i = held_items.size()-1; i >= 0; i--) + { + if (!preagent->matchesRoot(held_items[i], cur_reaction->index)) + continue; + if (linear_index(sel_items, held_items[i]) >= 0) + continue; + choice_items.push_back(held_items[i]); + } + + layer_objects[6]->setListLength(choice_items.size()); + + if (!choice_items.empty()) + { + layer_objects[4]->active = layer_objects[5]->active = false; + layer_objects[6]->active = true; + } + else if (layer_objects[6]->active) + { + layer_objects[6]->active = false; + layer_objects[5]->active = true; + } + } + } + } +}; + +IMPLEMENT_VMETHOD_INTERPOSE(advmode_contained_hook, feed); + static void enable_hook(color_ostream &out, VMethodInterposeLinkBase &hook, vector ¶meters) { if (vector_get(parameters, 1) == "disable") @@ -582,6 +649,10 @@ static command_result tweak(color_ostream &out, vector ¶meters) enable_hook(out, INTERPOSE_HOOK(dimension_thread_hook, subtractDimension), parameters); enable_hook(out, INTERPOSE_HOOK(dimension_cloth_hook, subtractDimension), parameters); } + else if (cmd == "advmode-contained") + { + enable_hook(out, INTERPOSE_HOOK(advmode_contained_hook, feed), parameters); + } else return CR_WRONG_USAGE;