From bb5d98e8959c6602d3fe31fb15d9fecb3b0f77fd Mon Sep 17 00:00:00 2001
From: Warmist
Does not export any native functions as of now. Instead, it calls lua code to perform the actual ordering of list items.
+This plugin exports some events to lua thus allowing to run lua functions +on DF world events.
+onReactionComplete(reaction,unit,input_items,input_reagents,output_items,call_native)
+Auto activates if detects reactions starting with LUA_HOOK_. Is called when reaction finishes.
+onItemContaminateWound(item,unit,wound,number1,number2)
+Is called when item tries to contaminate wound (e.g. stuck in).
+onProjItemCheckMovement(projectile)
+Is called when projectile moves.
+onProjItemCheckImpact(projectile,somebool)
+Is called when projectile hits something.
+onProjUnitCheckMovement(projectile)
+Is called when projectile moves.
+onProjUnitCheckImpact(projectile,somebool)
+Is called when projectile hits something.
+onWorkshopFillSidebarMenu(workshop,callnative)
+Is called when viewing a workshop in 'q' mode, to populate reactions, usefull for custom viewscreens for shops.
+postWorkshopFillSidebarMenu(workshop)
+Is called after calling (or not) native fillSidebarMenu(). Usefull for job button +tweaking (e.g. adding custom reactions)
+registerReaction(reaction_name,callback)
+Simplified way of using onReactionComplete; the callback is function (same params as event).
+removeNative(shop_name)
+Removes native choice list from the building.
+addReactionToShop(reaction_name,shop_name)
+Add a custom reaction to the building.
+Spawn dragon breath on each item attempt to contaminate wound:
++b=require "plugins.eventful" +b.onItemContaminateWound.one=function(item,unit,un_wound,x,y) + local flw=dfhack.maps.spawnFlow(unit.pos,6,0,0,50000) +end ++
Reaction complete example:
++b=require "plugins.eventful" + +b.onReactionComplete.one=function(reaction,unit,in_items,in_reag,out_items,call_native) + local pos=copyall(unit.pos) + -- spawn dragonbreath after 100 ticks + dfhack.timeout(100,"ticks",function() dfhack.maps.spawnFlow(pos,6,0,0,50000) end) + --do not call real item creation code + call_native.value=false +end ++
Granade example:
++b=require "plugins.eventful" +b.onProjItemCheckImpact.one=function(projectile) + -- you can check if projectile.item e.g. has correct material + dfhack.maps.spawnFlow(projectile.cur_pos,6,0,0,50000) +end ++
Integrated tannery:
+
+b=require "plugins.eventful"
+b.addReactionToShop("TAN_A_HIDE","LEATHERWORKS")
+
+Any files with the .lua extension placed into hack/scripts/* are automatically used by the DFHack core as commands. The matching command name consists of the name of the file sans @@ -3071,7 +3161,7 @@ The name argument should be the name stem, as
Note that this function lets errors propagate to the caller.
If a save directory contains a file called raw/init.lua, it is automatically loaded and executed every time the save is loaded. It can also define the following functions to be called by dfhack:
diff --git a/Lua API.rst b/Lua API.rst index a6bdca4ef..19ba7132d 100644 --- a/Lua API.rst +++ b/Lua API.rst @@ -2967,51 +2967,85 @@ on DF world events. List of events -------------- -1. onReactionComplete(reaction,unit,input_items,input_reagents,output_items,call_native) - auto activates if detects reactions starting with ``LUA_HOOK_``. Is called when reaction finishes. -2. onItemContaminateWound(item,unit,wound,number1,number2) - Is called when item tries to contaminate wound (e.g. stuck in) -3. onProjItemCheckMovement(projectile) - is called when projectile moves -4. onProjItemCheckImpact(projectile,somebool) - is called when projectile hits something -5. onProjUnitCheckMovement(projectile) - is called when projectile moves -6. onProjUnitCheckImpact(projectile,somebool) - is called when projectile hits something -7. onWorkshopFillSidebarMenu(workshop,callnative) - is called when viewing a workshop in 'q' mode, to populate reactions, usefull for custom viewscreens for shops -8. postWorkshopFillSidebarMenu(workshop) - is called after calling (or not) native fillSidebarMenu(). Usefull for job button tweaking (e.g. adding custom reactions) +1. ``onReactionComplete(reaction,unit,input_items,input_reagents,output_items,call_native)`` + + Auto activates if detects reactions starting with ``LUA_HOOK_``. Is called when reaction finishes. + +2. ``onItemContaminateWound(item,unit,wound,number1,number2)`` + + Is called when item tries to contaminate wound (e.g. stuck in). + +3. ``onProjItemCheckMovement(projectile)`` + + Is called when projectile moves. + +4. ``onProjItemCheckImpact(projectile,somebool)`` + + Is called when projectile hits something. + +5. ``onProjUnitCheckMovement(projectile)`` + + Is called when projectile moves. + +6. ``onProjUnitCheckImpact(projectile,somebool)`` + + Is called when projectile hits something. + +7. ``onWorkshopFillSidebarMenu(workshop,callnative)`` + + Is called when viewing a workshop in 'q' mode, to populate reactions, usefull for custom viewscreens for shops. + +8. ``postWorkshopFillSidebarMenu(workshop)`` + + Is called after calling (or not) native fillSidebarMenu(). Usefull for job button + tweaking (e.g. adding custom reactions) Functions --------- -1. registerReaction(reaction_name,callback) - simplified way of using onReactionComplete, the callback is function (same params as event) -2. removeNative(shop_name) - removes native choice list from the building -3. addReactionToShop(reaction_name,shop_name) - add a custom reaction to the building +1. ``registerReaction(reaction_name,callback)`` + + Simplified way of using onReactionComplete; the callback is function (same params as event). + +2. ``removeNative(shop_name)`` + + Removes native choice list from the building. + +3. ``addReactionToShop(reaction_name,shop_name)`` + + Add a custom reaction to the building. Examples -------- -Spawn dragon breath on each item attempt to contaminate wound: -:: +Spawn dragon breath on each item attempt to contaminate wound:: - b=require "plugins.eventful" + b=require "plugins.eventful" b.onItemContaminateWound.one=function(item,unit,un_wound,x,y) local flw=dfhack.maps.spawnFlow(unit.pos,6,0,0,50000) end -Reaction complete example: -:: +Reaction complete example:: + b=require "plugins.eventful" + b.onReactionComplete.one=function(reaction,unit,in_items,in_reag,out_items,call_native) local pos=copyall(unit.pos) - dfhack.timeout(100,"ticks",function() dfhack.maps.spawnFlow(pos,6,0,0,50000) end) -- spawn dragonbreath after 100 ticks - call_native.value=false --do not call real item creation code + -- spawn dragonbreath after 100 ticks + dfhack.timeout(100,"ticks",function() dfhack.maps.spawnFlow(pos,6,0,0,50000) end) + --do not call real item creation code + call_native.value=false end -Granade example: -:: +Granade example:: + b=require "plugins.eventful" b.onProjItemCheckImpact.one=function(projectile) -- you can check if projectile.item e.g. has correct material dfhack.maps.spawnFlow(projectile.cur_pos,6,0,0,50000) end -Integrated tannery: -:: +Integrated tannery:: + b=require "plugins.eventful" b.addReactionToShop("TAN_A_HIDE","LEATHERWORKS") diff --git a/NEWS b/NEWS index d9c184832..91eab0ec0 100644 --- a/NEWS +++ b/NEWS @@ -4,7 +4,8 @@ DFHack future - support for displaying active keybindings properly. - support for reusable widgets in lua screen library. - Maps::canStepBetween: returns whether you can walk between two tiles in one step. - - EventManager: monitors various in game events centrally so that individual plugins don't have to monitor the same things redundantly. + - EventManager: monitors various in game events centrally so that individual plugins + don't have to monitor the same things redundantly. Notable bugfixes: - autobutcher can be re-enabled again after being stopped. - stopped Dwarf Manipulator from unmasking vampires. @@ -28,6 +29,7 @@ DFHack future - stripcaged: mark items inside cages for dumping, eg caged goblin weapons. - soundsense-season: writes the correct season to gamelog.txt on world load. - create-items: spawn items + - fix/cloth-stockpile: fixes bug 5739; needs to be run after savegame load every time. New GUI scripts: - gui/guide-path: displays the cached path for minecart Guide orders. - gui/workshop-job: displays inputs of a workshop job and allows tweaking them. diff --git a/Readme.html b/Readme.html index d9a3d0602..8cd192f35 100644 --- a/Readme.html +++ b/Readme.html @@ -510,41 +510,42 @@ access DF memory and allow for easier development of new tools.Diagnoses and fixes issues with nonexistant 'items occupying site', usually caused by autodump bugs or other hacking mishaps.
fix/cloth-stockpile
+Fixes erratic behavior of cloth stockpiles by scanning material objects +in memory and patching up some invalid reference fields. Needs to be run +every time a save game is loaded; putting fix/cloth-stockpile enable +in dfhack.init makes it run automatically.
+It is a well known issue that Soundsense cannot detect the correct +current season when a savegame is loaded and has to play random +season music until a season switch occurs.
+This script registers a hook that prints the appropriate string +to gamelog.txt on every map load to fix this. For best results +call the script from dfhack.init.
+These tools work by displaying dialogs or overlays in the game window, and are mostly implemented by lua scripts.
Implemented by the manipulator plugin. To activate, open the unit screen and press 'l'.
@@ -2901,7 +2917,7 @@ cursor onto that cell instead of toggling it.
directly to the main dwarf mode screen.
The search plugin adds search to the Stocks, Animals, Trading, Stockpile, Noble (assignment candidates), Military (position candidates), Burrows (unit list), Rooms, Announcements, Job List and Unit List screens.
@@ -2931,7 +2947,7 @@ only fat or tallow by forbidding fats, then searching for fat/tallow, and using Permit Fats again while the list is filtered.The automaterial plugin makes building constructions (walls, floors, fortifications, etc) a little bit easier by saving you from having to trawl through long lists of materials each time you place one.
@@ -2958,14 +2974,27 @@ materials, it returns you back to this screen. If you use this along with severa enabled materials, you should be able to place complex constructions more conveniently.To use, bind to a key (the example config uses Alt-L) and activate in the 'k' mode.
-While active, use the suggested keys to switch the usual liquids parameters, and Enter -to select the target area and apply changes.
+This script is a gui front-end to the liquids plugin and works similar to it, +allowing you to add or remove water & magma, and create obsidian walls & floors. +Note that there is no undo support, and that bugs in this plugin have been +known to create pathfinding problems and heat traps.
+The b key changes how the affected area is selected. The default Rectangle +mode works by selecting two corners like any ordinary designation. The p +key chooses between adding water, magma, obsidian walls & floors, or just +tweaking flags.
+When painting liquids, it is possible to select the desired level with +-, +and choose between setting it exactly, only increasing or only decreasing +with s.
+In addition, f allows disabling or enabling the flowing water computations +for an area, and r operates on the "permanent flow" property that makes +rivers power water wheels even when full and technically not flowing.
+After setting up the desired operations using the described keys, use Enter to apply them.
To use, bind to a key (the example config uses Ctrl-M) and activate in the 'q' mode.
Lists mechanisms connected to the building, and their links. Navigating the list centers @@ -2975,7 +3004,7 @@ focus on the current one. Shift-Enter has an effect equivalent to pressing Enter re-entering the mechanisms ui.
Backed by the rename plugin, this script allows entering the desired name via a simple dialog in the game ui.
To use, bind to a key (the example config uses Alt-R) and activate in the 'q' mode, either immediately or after opening the assign owner page.
@@ -3006,7 +3035,7 @@ either immediately or after opening the assign owner page.
list, and allows unassigning them.
Bind to a key (the example config uses Ctrl-W), and activate in the Equip->View/Customize page of the military screen.
Depending on the cursor location, it rewrites all 'individual choice weapon' entries @@ -3017,7 +3046,7 @@ only that entry, and does it even if it is not 'individual choice'.
and may lead to inappropriate weapons being selected.Bind to a key (the example config uses Alt-P), and activate in the Hauling menu with the cursor over a Guide order.
@@ -3025,7 +3054,7 @@ the cursor over a Guide order.
computes it when the order is executed for the first time.
Bind to a key (the example config uses Alt-A), and activate with a job selected in a workshop in the 'q' mode.
@@ -3061,7 +3090,7 @@ and then try to change the input item type, now it won't let you select plan
you have to unset the material first.
Bind to a key (the example config uses Alt-W), and activate with a job selected in a workshop in the 'q' mode.
@@ -3108,7 +3137,7 @@ the current stock value. The bright green dashed line is the target
limit (maximum) and the dark green line is that minus the gap (minimum).
Bind to a key (the example config uses P), and activate when viewing a weapon rack in the 'q' mode.
@@ -3132,7 +3161,7 @@ the intended user. In order to aid in the choice, it shows the number
of currently assigned racks for every valid squad.
This script allows to perform jobs in adventure mode. For more complete help press '?' while script is running. It's most confortable to use this as a keybinding. (e.g. keybinding set Ctrl-T gui/advfort). Possible arguments:
@@ -3145,7 +3174,7 @@ implies -aThere are three ways to open this editor:
These plugins, when activated via configuration UI or by detecting certain structures in RAWs, modify the game engine behavior concerning the target objects to add features not otherwise present.
@@ -3171,20 +3200,20 @@ technical challenge, and do not represent any long-term plans to produce more similar modifications of the game.The siege-engine plugin enables siege engines to be linked to stockpiles, and aimed at an arbitrary rectangular area across Z levels, instead of the original four directions. Also, catapults can be ordered to load arbitrary objects, not just stones.
Siege engines are a very interesting feature, but sadly almost useless in the current state because they haven't been updated since 2D and can only aim in four directions. This is an attempt to bring them more up to date until Toady has time to work on it. Actual improvements, e.g. like making siegers bring their own, are something only Toady can do.
The configuration front-end to the plugin is implemented by the gui/siege-engine script. Bind it to a key (the example config uses Alt-A) and activate after selecting a siege engine in 'q' mode.
@@ -3207,7 +3236,7 @@ menu.The power-meter plugin implements a modified pressure plate that detects power being supplied to gear boxes built in the four adjacent N/S/W/E tiles.
The configuration front-end is implemented by the gui/power-meter script. Bind it to a @@ -3218,11 +3247,11 @@ in the build menu.
configuration page, but configures parameters relevant to the modded power meter building.The steam-engine plugin detects custom workshops with STEAM_ENGINE in their token, and turns them into real steam engines.
The vanilla game contains only water wheels and windmills as sources of power, but windmills give relatively little power, and water wheels require flowing water, which must either be a real river and thus immovable and @@ -3233,7 +3262,7 @@ it can be done just by combining existing features of the game engine in a new way with some glue code and a bit of custom logic.
The workshop needs water as its input, which it takes via a passable floor tile below it, like usual magma workshops do. The magma version also needs magma.
@@ -3257,7 +3286,7 @@ short axles that can be built later than both of the engines.In order to operate the engine, queue the Stoke Boiler job (optionally on repeat). A furnace operator will come, possibly bringing a bar of fuel, and perform it. As a result, a "boiling water" item will appear @@ -3288,7 +3317,7 @@ decrease it by further 4%, and also decrease the whole steam use rate by 10%.
The engine must be constructed using barrel, pipe and piston from fire-safe, or in the magma version magma-safe metals.
During operation weak parts get gradually worn out, and @@ -3297,7 +3326,7 @@ toppled during operation by a building destroyer, or a tantruming dwarf.
It should be safe to load and view engine-using fortresses from a DF version without DFHack installed, except that in such case the engines won't work. However actually making modifications @@ -3308,7 +3337,7 @@ being generated.
This plugin makes reactions with names starting with SPATTER_ADD_
produce contaminants on the items instead of improvements. The produced
contaminants are immune to being washed away by water or destroyed by
diff --git a/Readme.rst b/Readme.rst
index 236eafb01..bc831e4a6 100644
--- a/Readme.rst
+++ b/Readme.rst
@@ -1773,6 +1773,12 @@ Scripts in this subdirectory fix various bugs and issues, some of them obscure.
Diagnoses and fixes issues with nonexistant 'items occupying site', usually
caused by autodump bugs or other hacking mishaps.
+* fix/cloth-stockpile
+
+ Fixes erratic behavior of cloth stockpiles by scanning material objects
+ in memory and patching up some invalid reference fields. Needs to be run
+ every time a save game is loaded; putting ``fix/cloth-stockpile enable``
+ in ``dfhack.init`` makes it run automatically.
gui/*
=====
@@ -2032,6 +2038,17 @@ Exemples::
create-items bar CREATURE:CAT:SOAP
create-items bar adamantine
+soundsense-season
+=================
+
+It is a well known issue that Soundsense cannot detect the correct
+current season when a savegame is loaded and has to play random
+season music until a season switch occurs.
+
+This script registers a hook that prints the appropriate string
+to gamelog.txt on every map load to fix this. For best results
+call the script from ``dfhack.init``.
+
=======================
In-game interface tools
=======================
@@ -2185,8 +2202,25 @@ To use, bind to a key (the example config uses Alt-L) and activate in the 'k' mo
.. image:: images/liquids.png
-While active, use the suggested keys to switch the usual liquids parameters, and Enter
-to select the target area and apply changes.
+This script is a gui front-end to the liquids plugin and works similar to it,
+allowing you to add or remove water & magma, and create obsidian walls & floors.
+Note that there is **no undo support**, and that bugs in this plugin have been
+known to create pathfinding problems and heat traps.
+
+The ``b`` key changes how the affected area is selected. The default *Rectangle*
+mode works by selecting two corners like any ordinary designation. The ``p``
+key chooses between adding water, magma, obsidian walls & floors, or just
+tweaking flags.
+
+When painting liquids, it is possible to select the desired level with ``+-``,
+and choose between setting it exactly, only increasing or only decreasing
+with ``s``.
+
+In addition, ``f`` allows disabling or enabling the flowing water computations
+for an area, and ``r`` operates on the "permanent flow" property that makes
+rivers power water wheels even when full and technically not flowing.
+
+After setting up the desired operations using the described keys, use ``Enter`` to apply them.
gui/mechanisms
From 03b91ca26c3e5eb82c51fa57ea6944c99e5dec19 Mon Sep 17 00:00:00 2001
From: Alexander Gavrilov
Is called when projectile hits something.
onWorkshopFillSidebarMenu(workshop,callnative)
-Is called when viewing a workshop in 'q' mode, to populate reactions, usefull for custom viewscreens for shops.
+Is called when viewing a workshop in 'q' mode, to populate reactions, useful for custom viewscreens for shops.
postWorkshopFillSidebarMenu(workshop)
-Is called after calling (or not) native fillSidebarMenu(). Usefull for job button +
Is called after calling (or not) native fillSidebarMenu(). Useful for job button tweaking (e.g. adding custom reactions)
Granade example:
+Grenade example:
b=require "plugins.eventful"
b.onProjItemCheckImpact.one=function(projectile)
diff --git a/Lua API.rst b/Lua API.rst
index 19ba7132d..6d4e6b51b 100644
--- a/Lua API.rst
+++ b/Lua API.rst
@@ -2993,11 +2993,11 @@ List of events
7. ``onWorkshopFillSidebarMenu(workshop,callnative)``
- Is called when viewing a workshop in 'q' mode, to populate reactions, usefull for custom viewscreens for shops.
+ Is called when viewing a workshop in 'q' mode, to populate reactions, useful for custom viewscreens for shops.
8. ``postWorkshopFillSidebarMenu(workshop)``
- Is called after calling (or not) native fillSidebarMenu(). Usefull for job button
+ Is called after calling (or not) native fillSidebarMenu(). Useful for job button
tweaking (e.g. adding custom reactions)
Functions
@@ -3036,7 +3036,7 @@ Reaction complete example::
call_native.value=false
end
-Granade example::
+Grenade example::
b=require "plugins.eventful"
b.onProjItemCheckImpact.one=function(projectile)
From f55030909f83c54b5b74d085d0dd1253b60e210e Mon Sep 17 00:00:00 2001
From: Quietust
Date: Wed, 27 Feb 2013 11:09:06 -0600
Subject: [PATCH 08/20] Add createItem plugin, spawns an item at the selected
unit's feet
---
plugins/CMakeLists.txt | 1 +
plugins/createitem.cpp | 234 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 235 insertions(+)
create mode 100644 plugins/createitem.cpp
diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt
index f2bf4d4a4..65a550018 100644
--- a/plugins/CMakeLists.txt
+++ b/plugins/CMakeLists.txt
@@ -136,6 +136,7 @@ if (BUILD_SUPPORTED)
DFHACK_PLUGIN(autoSyndrome autoSyndrome.cpp)
DFHACK_PLUGIN(trueTransformation trueTransformation.cpp)
DFHACK_PLUGIN(infiniteSky infiniteSky.cpp)
+ DFHACK_PLUGIN(createitem createitem.cpp)
endif()
diff --git a/plugins/createitem.cpp b/plugins/createitem.cpp
new file mode 100644
index 000000000..722932a99
--- /dev/null
+++ b/plugins/createitem.cpp
@@ -0,0 +1,234 @@
+// Create arbitrary items
+
+#include "Core.h"
+#include "Console.h"
+#include "Export.h"
+#include "PluginManager.h"
+#include "MiscUtils.h"
+
+#include "modules/Maps.h"
+#include "modules/Gui.h"
+#include "modules/Items.h"
+#include "modules/Materials.h"
+
+#include "DataDefs.h"
+#include "df/world.h"
+#include "df/ui.h"
+#include "df/unit.h"
+#include "df/historical_entity.h"
+#include "df/world_site.h"
+#include "df/item.h"
+#include "df/creature_raw.h"
+#include "df/caste_raw.h"
+#include "df/reaction_reagent.h"
+#include "df/reaction_product_itemst.h"
+
+using namespace std;
+using namespace DFHack;
+
+using df::global::world;
+using df::global::ui;
+
+DFHACK_PLUGIN("createitem");
+
+command_result df_createitem (color_ostream &out, vector & parameters);
+
+DFhackCExport command_result plugin_init (color_ostream &out, std::vector &commands)
+{
+ commands.push_back(PluginCommand("createitem", "Create arbitrary item at the selected unit's feet.", df_createitem));
+ return CR_OK;
+}
+
+DFhackCExport command_result plugin_shutdown ( color_ostream &out )
+{
+ return CR_OK;
+}
+
+bool makeItem (df::reaction_product_itemst *prod, df::unit *unit, int hand = 0)
+{
+ vector out_items;
+ vector in_reag;
+ vector in_items;
+
+ prod->produce(unit, &out_items, &in_reag, &in_items, 1, df::job_skill::NONE, ui->main.fortress_entity, df::world_site::find(ui->site_id));
+ if (!out_items.size())
+ return false;
+ for (size_t i = 0; i < out_items.size(); i++)
+ {
+ out_items[i]->moveToGround(unit->pos.x, unit->pos.y, unit->pos.z);
+ if (hand)
+ out_items[i]->setGloveHandedness(hand);
+ }
+ return true;
+}
+
+command_result df_createitem (color_ostream &out, vector & parameters)
+{
+ string item_str, material_str;
+ df::item_type item_type;
+ int16_t item_subtype;
+ int16_t mat_type;
+ int32_t mat_index;
+
+ if (parameters.size() != 2)
+ {
+ out.print("Syntax: createitem ITEM_TYPE:ITEM_SUBTYPE MATERIAL:ETC\n");
+ return CR_WRONG_USAGE;
+ }
+ item_str = parameters[0];
+ material_str = parameters[1];
+
+ ItemTypeInfo item;
+ MaterialInfo material;
+ vector tokens;
+
+ if (!item.find(item_str))
+ {
+ out.printerr("Unrecognized item type!\n");
+ return CR_FAILURE;
+ }
+ item_type = item.type;
+ item_subtype = item.subtype;
+ switch (item.type)
+ {
+ case df::item_type::INSTRUMENT:
+ case df::item_type::TOY:
+ case df::item_type::WEAPON:
+ case df::item_type::ARMOR:
+ case df::item_type::SHOES:
+ case df::item_type::SHIELD:
+ case df::item_type::HELM:
+ case df::item_type::GLOVES:
+ case df::item_type::AMMO:
+ case df::item_type::PANTS:
+ case df::item_type::SIEGEAMMO:
+ case df::item_type::TRAPCOMP:
+ case df::item_type::TOOL:
+ if (item_subtype == -1)
+ {
+ out.printerr("You must specify a valid subtype!\n");
+ return CR_FAILURE;
+ }
+ default:
+ if (!material.find(material_str))
+ {
+ out.printerr("Unrecognized material!\n");
+ return CR_FAILURE;
+ }
+ mat_type = material.type;
+ mat_index = material.index;
+ break;
+
+ case df::item_type::REMAINS:
+ case df::item_type::FISH:
+ case df::item_type::FISH_RAW:
+ case df::item_type::VERMIN:
+ case df::item_type::PET:
+ case df::item_type::EGG:
+ split_string(&tokens, material_str, ":");
+ if (tokens.size() != 2)
+ {
+ out.printerr("You must specify a creature ID and caste for this item type!\n");
+ return CR_FAILURE;
+ }
+
+ mat_type = mat_index = -1;
+ for (size_t i = 0; i < world->raws.creatures.all.size(); i++)
+ {
+ df::creature_raw *creature = world->raws.creatures.all[i];
+ if (creature->creature_id == tokens[0])
+ {
+ for (size_t j = 0; j < creature->caste.size(); j++)
+ {
+ df::caste_raw *caste = creature->caste[j];
+ if (creature->caste[j]->caste_id == tokens[1])
+ {
+ mat_type = i;
+ mat_index = j;
+ break;
+ }
+ }
+ if (mat_type == -1)
+ {
+ out.printerr("The creature you specified has no such caste!\n");
+ return CR_FAILURE;
+ }
+ }
+ }
+ if (mat_type == -1)
+ {
+ out.printerr("Unrecognized creature ID!\n");
+ return CR_FAILURE;
+ }
+ break;
+
+ case df::item_type::CORPSE:
+ case df::item_type::CORPSEPIECE:
+ case df::item_type::FOOD:
+ out.printerr("Cannot create that type of item!\n");
+ return CR_FAILURE;
+ break;
+ }
+
+ CoreSuspender suspend;
+
+ df::unit *unit = Gui::getSelectedUnit(out, true);
+ if (!unit)
+ {
+ out.printerr("No unit selected!\n");
+ return CR_FAILURE;
+ }
+ if (!Maps::IsValid())
+ {
+ out.printerr("Map is not available.\n");
+ return CR_FAILURE;
+ }
+ df::map_block *block = Maps::getTileBlock(unit->pos.x, unit->pos.y, unit->pos.z);
+ if (block == NULL)
+ {
+ out.printerr("Unit does not reside in a valid map block, somehow?\n");
+ return CR_FAILURE;
+ }
+
+ df::reaction_product_itemst *prod = df::allocate();
+ prod->item_type = item_type;
+ prod->item_subtype = item_subtype;
+ prod->mat_type = mat_type;
+ prod->mat_index = mat_index;
+ prod->probability = 100;
+ prod->count = 1;
+ switch (item_type)
+ {
+ case df::item_type::BAR:
+ case df::item_type::POWDER_MISC:
+ case df::item_type::LIQUID_MISC:
+ case df::item_type::DRINK:
+ prod->product_dimension = 150;
+ break;
+ case df::item_type::THREAD:
+ prod->product_dimension = 15000;
+ break;
+ case df::item_type::CLOTH:
+ prod->product_dimension = 10000;
+ break;
+ default:
+ prod->product_dimension = 1;
+ break;
+ }
+
+ bool result;
+#if 1
+ // Workaround for DF issue #0006273
+ if (item_type == df::item_type::GLOVES)
+ result = makeItem(prod, unit, 1) && makeItem(prod, unit, 2);
+ else
+#endif
+ result = makeItem(prod, unit);
+
+ if (!result)
+ {
+ out.printerr("Failed to create item!\n");
+ return CR_FAILURE;
+ }
+ return CR_OK;
+}
From f418bce60e1a0dcdde216484b6d175ed7805ffb0 Mon Sep 17 00:00:00 2001
From: Quietust
Date: Wed, 27 Feb 2013 11:20:49 -0600
Subject: [PATCH 09/20] Document new createitem plugin
---
Readme.html | 543 +++++++++++++++++++++++++++-------------------------
Readme.rst | 20 ++
2 files changed, 303 insertions(+), 260 deletions(-)
diff --git a/Readme.html b/Readme.html
index 8cd192f35..a3a2ab9c1 100644
--- a/Readme.html
+++ b/Readme.html
@@ -380,172 +380,173 @@ access DF memory and allow for easier development of new tools.
changevein
changeitem
colonies
-deramp (by zilpin)
-feature
-liquids
-liquids-here
-tiletypes
-tiletypes-commands
-tiletypes-here
-tiletypes-here-point
-tubefill
-extirpate
-grow
-immolate
-regrass
-weather
+createitem
+deramp (by zilpin)
+feature
+liquids
+liquids-here
+tiletypes
+tiletypes-commands
+tiletypes-here
+tiletypes-here-point
+tubefill
+extirpate
+grow
+immolate
+regrass
+weather
-Map inspection
-- cursecheck
-- flows
-- probe
-- prospect
-- Pre-embark estimate
+- Map inspection
-- Designations
-- burrow
-- digv
-- digvx
-- digl
-- diglx
-- digexp
-- digcircle
-- digtype
-- filltraffic
-- alltraffic
-- getplants
+- Designations
-- Cleanup and garbage disposal
-- clean
-- spotclean
-- autodump
-- autodump-destroy-here
-- autodump-destroy-item
-- cleanowned
+- Cleanup and garbage disposal
-- Bugfixes
-- drybuckets
-- fixdiplomats
-- fixmerchants
-- fixveins
-- tweak
-- fix-armory
+- Bugfixes
-- Mode switch and reclaim
-- lair
-- mode
+- Mode switch and reclaim
-- Visualizer and data export
-- ssense / stonesense
-- mapexport
-- dwarfexport
+- Visualizer and data export
-- Job management
-- job
-- job-material
-- job-duplicate
-- workflow
-- Function
-- Constraint format
-- Constraint examples
+- Job management
-- Fortress activity management
-- seedwatch
-- zone
-- Usage with single units
-- Usage with filters
-- Mass-renaming
-- Cage zones
-- Examples
+- Fortress activity management
-- Other
-- Scripts
-- fix/*
-- gui/*
-- binpatch
-- quicksave
-- setfps
-- siren
-- growcrops
-- removebadthoughts
-- slayrace
-- magmasource
-- digfort
-- superdwarf
-- drainaquifer
-- deathcause
-- lua
-- embark
-- lever
-- stripcaged
-- create-items
-- soundsense-season
+- Scripts
-- In-game interface tools
-- Dwarf Manipulator
-- Search
-- AutoMaterial
-- gui/liquids
-- gui/mechanisms
-- gui/rename
-- gui/room-list
-- gui/choose-weapons
-- gui/guide-path
-- gui/workshop-job
-- gui/workflow
-- gui/assign-rack
-- gui/advfort
-- gui/gm-editor
+- In-game interface tools
-- Behavior Mods
-- Siege Engine
-- Rationale
-- Configuration UI
+- Behavior Mods
@@ -1027,13 +1028,35 @@ crafters/haulers.
Allows creating new items of arbitrary types and made of arbitrary materials. +Any items created are spawned at the feet of the selected unit.
+Specify the item and material information as you would indicate them in custom reaction raws, with the following differences: +* Separate the item and material with a space rather than a colon +* If the item has no subtype, omit the :NONE +* If the item is REMAINS, FISH, FISH_RAW, VERMIN, PET, or EGG, specify a CREATURE:CASTE pair instead of a material token.
+Corpses, body parts, and prepared meals cannot be created using this tool.
+Removes all ramps designated for removal from the map. This is useful for replicating the old channel digging designation. It also removes any and all 'down ramps' that can remain after a cave-in (you don't have to designate anything for that to happen).
Enables management of map features.
Allows adding magma, water and obsidian to the game. It replaces the normal dfhack command line and can't be used from a hotkey. Settings will be remembered as long as dfhack runs. Intended for use in combination with the command @@ -1071,13 +1094,13 @@ temperatures (creating heat traps). You've been warned.
Run the liquid spawner with the current/last settings made in liquids (if no settings in liquids were made it paints a point of 7/7 magma by default).
Intended to be used as keybinding. Requires an active in-game cursor.
Can be used for painting map tiles and is an interactive command, much like liquids.
The tool works with two set of options and a brush. The brush determines which @@ -1138,27 +1161,27 @@ up.
For more details, see the 'help' command while using this.
Runs tiletypes commands, separated by ;. This makes it possible to change tiletypes modes from a hotkey.
Apply the current tiletypes options at the in-game cursor position, including the brush. Can be used from a hotkey.
Apply the current tiletypes options at the in-game cursor position to a single tile. Can be used from a hotkey.
Fills all the adamantine veins again. Veins that were empty will be filled in too, but might still trigger a demon invasion (this is a known bug).
A tool for getting rid of trees and shrubs. By default, it only kills a tree/shrub under the cursor. The plants are turned into ashes instantly.
Options:
@@ -1178,20 +1201,20 @@ a tree/shrub under the cursor. The plants are turned into ashes instantly.Very similar to extirpate, but additionally sets the plants on fire. The fires can and will spread ;)
Prints the current weather map by default.
Also lets you change the current weather to 'clear sky', 'rainy' or 'snowing'.
Options:
@@ -1212,9 +1235,9 @@ can and will spread ;)Checks a single map tile or the whole map/world for cursed creatures (ghosts, vampires, necromancers, werebeasts, zombies).
With an active in-game cursor only the selected tile will be observed. @@ -1269,17 +1292,17 @@ of curses, for example.
A tool for checking how many tiles contain flowing liquids. If you suspect that your magma sea leaks into HFS, you can use this tool to be sure without revealing the map.
Prints a big list of all the present minerals and plants. By default, only the visible part of the map is scanned.
Options:
@@ -1298,7 +1321,7 @@ the visible part of the map is scanned.If prospect is called during the embark selection screen, it displays an estimate of layer stone availability.
This reveals the map. By default, HFS will remain hidden so that the demons don't spawn. You can use 'reveal hell' to reveal everything. With hell revealed, you won't be able to unpause until you hide the map again. If you really want @@ -1332,34 +1355,34 @@ to unpause with hell revealed, use 'reveal demons'.
you move. When you use it this way, you don't need to run 'unreveal'.This command will hide the whole map and then reveal all the tiles that have a path to the in-game cursor.
When you use reveal, it saves information about what was/wasn't visible before revealing everything. Unreveal uses this information to hide things again. This command throws away the information. For example, use in cases where you abandoned with the fort revealed and no longer want the data.
Miscellaneous burrow control. Allows manipulating burrows and automated burrow expansion while digging.
Options:
@@ -1407,17 +1430,17 @@ Digging 1-wide corridors with the miner inside the burrow is SLOW.Designates a whole vein for digging. Requires an active in-game cursor placed over a vein tile. With the 'x' option, it will traverse z-levels (putting stairs between the same-material tiles).
Designates layer stone for digging. Requires an active in-game cursor placed over a layer stone tile. With the 'x' option, it will traverse z-levels (putting stairs between the same-material tiles). With the 'undo' option it @@ -1425,11 +1448,11 @@ will remove the dig designation instead (if you realize that digging out a 50 z-level deep layer was not such a good idea after all).
This command can be used for exploratory mining.
See: http://df.magmawiki.com/index.php/DF2010:Exploratory_mining
There are two variables that can be set: pattern and filter.
@@ -1492,7 +1515,7 @@ z-level deep layer was not such a good idea after all).A command for easy designation of filled and hollow circles. It has several types of options.
Shape:
@@ -1555,7 +1578,7 @@ repeats with the last selected parameters.For every tile on the map of the same vein type as the selected tile, this command designates it to have the same designation as the selected tile. If the selected tile has no designation, they will be dig designated. If an argument is given, the designation of the selected tile is ignored, and all appropriate tiles are set to the specified designation.
Options:
@@ -1583,7 +1606,7 @@ If an argument is given, the designation of the selected tile is ignored, and alSet traffic designations using flood-fill starting at the cursor.
Traffic Type Codes:
@@ -1622,7 +1645,7 @@ If an argument is given, the designation of the selected tile is ignored, and al 'filltraffic H' - When used in a room with doors, it will set traffic to HIGH in just that room.
Set traffic designations for every single tile of the map (useful for resetting traffic designations).
Traffic Type Codes:
@@ -1646,7 +1669,7 @@ If an argument is given, the designation of the selected tile is ignored, and al 'alltraffic N' - Set traffic to 'normal' for all tiles.
Cleans all the splatter that get scattered all over the map, items and creatures. In an old fortress, this can significantly reduce FPS lag. It can also spoil your !!FUN!!, so think before you use it.
@@ -1709,12 +1732,12 @@ also spoil your !!FUN!!, so think before you use it.Works like 'clean map snow mud', but only for the tile under the cursor. Ideal if you want to keep that bloody entrance 'clean map' would clean up.
This utility lets you quickly move all items designated to be dumped. Items are instantly moved to the cursor position, the dump flag is unset, and the forbid flag is set, as if it had been dumped normally. @@ -1741,17 +1764,17 @@ Be aware that any active dump item tasks still point at the item.
Destroy items marked for dumping under cursor. Identical to autodump destroy-here, but intended for use as keybinding.
Destroy the selected item. The item may be selected in the 'k' list, or inside a container. If called again before the game is resumed, cancels destroy.
Confiscates items owned by dwarfs. By default, owned food on the floor and rotten items are confistacted and dumped.
Options:
@@ -1785,13 +1808,13 @@ worn items with 'X' damage and above.This utility removes water from all buckets in your fortress, allowing them to be safely used for making lye.
Up to version 0.31.12, Elves only sent Diplomats to your fortress to propose tree cutting quotas due to a bug; once that bug was fixed, Elves stopped caring about excess tree cutting. This command adds a Diplomat position to all Elven @@ -1800,19 +1823,19 @@ to violate them and potentially start wars) in case you haven't already modified your raws accordingly.
This command adds the Guild Representative position to all Human civilizations, allowing them to make trade agreements (just as they did back in 0.28.181.40d and earlier) in case you haven't already modified your raws accordingly.
Removes invalid references to mineral inclusions and restores missing ones. Use this if you broke your embark with tools like tiletypes, or if you accidentally placed a construction on top of a valuable mineral floor.
Contains various tweaks for minor bugs.
One-shot subcommands:
Enables a fix for storage of squad equipment in barracks.
Specifically, it prevents your haulers from moving squad equipment to stockpiles, and instead queues jobs to store it on weapon racks, @@ -1972,9 +1995,9 @@ these rules is intended by Toady; the rest are invented by this plugin.
This command allows you to mark the map as 'monster lair', preventing item scatter on abandon. When invoked as 'lair reset', it does the opposite.
Unlike reveal, this command doesn't save the information about tiles - you @@ -1994,7 +2017,7 @@ won't be able to restore state of real monster lairs using 'lair reset'.
An isometric visualizer that runs in a second window. This requires working graphics acceleration and at least a dual core CPU (otherwise it will slow down DF).
@@ -2029,19 +2052,19 @@ thread: http://df.magmawiki.com/index.php/Utility:Stonesense/Content_repositoryCommand for general job query and manipulation.
Alter the material of the selected job.
Invoked as:
@@ -2078,7 +2101,7 @@ over the first available choice with the matching material.
Manage control of repeat jobs.
Usage:
@@ -2121,7 +2144,7 @@ this list can be copied to a file, and then reloaded using the
When the plugin is enabled, it protects all repeat jobs from removal. If they do disappear due to any cause, they are immediately re-added to their workshop and suspended.
@@ -2134,7 +2157,7 @@ the frequency of jobs being toggled. in the game UI.The contstraint spec consists of 4 parts, separated with '/' characters:
ITEM[:SUBTYPE]/[GENERIC_MAT,...]/[SPECIFIC_MAT:...]/[LOCAL,<quality>] @@ -2163,7 +2186,7 @@ be used to ignore imported items or items below a certain quality.
Keep metal bolts within 900-1000, and wood/bone within 150-200.
workflow amount AMMO:ITEM_AMMO_BOLTS/METAL 1000 100 @@ -2212,15 +2235,15 @@ workflow count CRAFTS///LOCAL,EXCEPTIONAL 100 90
Tool for turning cooking of seeds and plants on/off depending on how much you have of them.
See 'seedwatch help' for detailed description.
Helps a bit with managing activity zones (pens, pastures and pits) and cages.
Options:
@@ -2319,7 +2342,7 @@ for war/hunt). Negatable.
One convenient way to use the zone tool is to bind the command 'zone assign' to a hotkey, maybe also the command 'zone set'. Place the in-game cursor over a pen/pasture or pit, use 'zone set' to mark it. Then you can select units @@ -2328,7 +2351,7 @@ and use 'zone assign' to assign them to their new home. Allows pitting your own dwarves, by the way.
All filters can be used together with the 'assign' command.
Restrictions: It's not possible to assign units who are inside built cages or chained because in most cases that won't be desirable anyways. @@ -2346,14 +2369,14 @@ are not properly added to your own stocks; slaughtering them should work).
Most filters can be negated (e.g. 'not grazer' -> race is not a grazer).
Using the 'nick' command you can set the same nickname for multiple units. If used without 'assign', 'all' or 'count' it will rename all units in the current default target zone. Combined with 'assign', 'all' or 'count' (and further optional filters) it will rename units matching the filter conditions.
Using the 'tocages' command you can assign units to a set of cages, for example a room next to your butcher shop(s). They will be spread evenly among available cages to optimize hauling to and butchering from them. For this to work you need @@ -2364,7 +2387,7 @@ would make no sense, but can be used together with 'nick' or 'remnick' and all the usual filters.
Assigns unpastured female egg-layers to nestbox zones. Requires that you create pen/pasture zones above nestboxes. If the pen is bigger than 1x1 the nestbox must be in the top left corner. Only 1 unit will be assigned per pen, regardless @@ -2419,7 +2442,7 @@ frames between runs.
Assigns lifestock for slaughter once it reaches a specific count. Requires that you add the target race(s) to a watch list. Only tame units will be processed.
Named units will be completely ignored (to protect specific animals from @@ -2527,7 +2550,7 @@ autobutcher.bat
Makes cats just multiply. It is not a good idea to run this more than once or twice.