Skip to content

Commit 9c37a3a

Browse files
committed
Add "createitem inspect" subcommand
1 parent be1bd54 commit 9c37a3a

3 files changed

Lines changed: 37 additions & 10 deletions

File tree

docs/Plugins.rst

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2635,25 +2635,34 @@ Usage:
26352635

26362636
createitem
26372637
==========
2638-
Allows creating new items of arbitrary types and made of arbitrary materials.
2639-
By default, items created are spawned at the feet of the selected unit.
2638+
Allows creating new items of arbitrary types and made of arbitrary materials. A
2639+
unit must be selected in-game to use this command. By default, items created are
2640+
spawned at the feet of the selected unit.
26402641

26412642
Specify the item and material information as you would indicate them in
26422643
custom reaction raws, with the following differences:
26432644

26442645
* Separate the item and material with a space rather than a colon
2645-
* If the item has no subtype, omit the :NONE
2646-
* If the item is REMAINS, FISH, FISH_RAW, VERMIN, PET, or EGG,
2647-
specify a CREATURE:CASTE pair instead of a material token.
2646+
* If the item has no subtype, the ``:NONE`` can be omitted
2647+
* If the item is ``REMAINS``, ``FISH``, ``FISH_RAW``, ``VERMIN``, ``PET``, or ``EGG``,
2648+
specify a ``CREATURE:CASTE`` pair instead of a material token.
26482649

26492650
Corpses, body parts, and prepared meals cannot be created using this tool.
26502651

2651-
Examples::
2652+
To obtain the item and material tokens of an existing item, run
2653+
``createitem inspect``. Its output can be passed directly as arguments to
2654+
``createitem`` to create new matching items, as long as the item type is
2655+
supported.
2656+
2657+
Examples:
2658+
2659+
* Create 2 pairs of steel gauntlets::
26522660

26532661
createitem GLOVES:ITEM_GLOVES_GAUNTLETS INORGANIC:STEEL 2
2654-
Create 2 pairs of steel gauntlets.
2662+
2663+
* Create tower-cap logs::
2664+
26552665
createitem WOOD PLANT_MAT:TOWER_CAP:WOOD
2656-
Create tower-cap logs.
26572666

26582667
For more examples, :wiki:`see this wiki page <Utility:DFHack/createitem>`.
26592668

docs/changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
3838
- `stockpiles`: fixed a crash when loading food stockpiles
3939

4040
## Misc Improvements
41+
- `createitem`: added an ``inspect`` subcommand to print the item and material tokens of existing items, which can be used to create additional matching items
4142
- `embark-assistant`: added support for searching for taller waterfalls (up to 50 z-levels tall)
4243

4344
# 0.47.04-r2

plugins/createitem.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,12 @@ DFhackCExport command_result plugin_init (color_ostream &out, std::vector<Plugin
5353
" PET, and EGG, replace this with a creature ID and caste.\n"
5454
" [count] - How many of the item you wish to create.\n"
5555
"\n"
56+
"To obtain the item and material of an existing item, run \n"
57+
"'createitem inspect' with that item selected in-game.\n"
58+
"\n"
5659
"To use this command, you must select which unit will create the items.\n"
5760
"By default, items created will be placed at that unit's feet.\n"
58-
"To change this, type 'createitem <destination>'.\n"
61+
"To change this, run 'createitem <destination>'.\n"
5962
"Valid destinations:\n"
6063
"* floor - Place items on floor beneath maker's feet.\n"
6164
"* item - Place items inside selected container.\n"
@@ -142,7 +145,21 @@ command_result df_createitem (color_ostream &out, vector <string> & parameters)
142145

143146
if (parameters.size() == 1)
144147
{
145-
if (parameters[0] == "floor")
148+
if (parameters[0] == "inspect")
149+
{
150+
CoreSuspender suspend;
151+
df::item *item = Gui::getSelectedItem(out);
152+
if (!item)
153+
{
154+
return CR_FAILURE;
155+
}
156+
157+
ItemTypeInfo iinfo(item->getType(), item->getSubtype());
158+
MaterialInfo minfo(item->getMaterial(), item->getMaterialIndex());
159+
out.print("%s %s\n", iinfo.getToken().c_str(), minfo.getToken().c_str());
160+
return CR_OK;
161+
}
162+
else if (parameters[0] == "floor")
146163
{
147164
dest_container = -1;
148165
dest_building = -1;

0 commit comments

Comments
 (0)