Skip to content

Commit 508fa2d

Browse files
authored
Merge branch 'develop' into uniformed-filter
2 parents a689c32 + 7b20900 commit 508fa2d

12 files changed

Lines changed: 735 additions & 41 deletions

File tree

docs/about/Authors.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ Omniclasm
163163
Ong Ying Gao ong-yinggao98
164164
oorzkws oorzkws
165165
OwnageIsMagic OwnageIsMagic
166+
pajawojciech pajawojciech
166167
palenerd dlmarquis
167168
PassionateAngler PassionateAngler
168169
Patrik Lundell PatrikLundell

docs/changelog.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ Template for new versions:
5757
## New Tools
5858

5959
## New Features
60+
- `orders`: added search overlay to find and navigate to matching manager orders with arrow indicators
6061
- `sort`: added ``Uniformed`` filter to squad assignment screen to filter dwarves with mining, woodcutting, or hunting labors
6162
- `sort`: Add death cause button to dead/missing tab in the creatures screen
6263

@@ -68,8 +69,14 @@ Template for new versions:
6869
## Documentation
6970

7071
## API
72+
- Added ``Maps::addMaterialSpatter``: add a spatter of the specified material + state to the indicated tile, returning whatever amount wouldn't fit in the tile.
73+
- Added ``Maps::addItemSpatter``: add a spatter of the specified item + material + growth print to the indicated tile, returning whatever amount wouldn't fit in the tile.
74+
- Added ``Items::pickGrowthPrint``: given a plant material and a growth index, returns the print variant corresponding to the current in-game time.
75+
- Added ``Items::useStandardMaterial``: given an item type, returns true if the item is made of a specific material and false if it has a race and caste instead.
7176

7277
## Lua
78+
- Added ``Maps::addMaterialSpatter`` as ``dfhack.maps.addMaterialSpatter``.
79+
- Added ``Maps::addItemSpatter`` as ``dfhack.maps.addItemSpatter``.
7380

7481
## Removed
7582

@@ -110,6 +117,7 @@ Template for new versions:
110117
## Documentation
111118

112119
## API
120+
- ``dfhack.job.getManagerOrderName``: New function to get the display name of a manager order
113121

114122
## Lua
115123

docs/dev/Lua API.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,6 +1430,10 @@ Job module
14301430

14311431
Returns the job's description, as seen in the Units and Jobs screens.
14321432

1433+
* ``dfhack.job.getManagerOrderName(manager_order)``
1434+
1435+
Returns the manager order's description, as seen in the Work orders screen.
1436+
14331437
Hotkey module
14341438
-------------
14351439

@@ -2486,6 +2490,22 @@ Maps module
24862490
Removes an aquifer from the given tile position.
24872491
Returns *true* or *false* depending on success.
24882492

2493+
* ``dfhack.maps.addMaterialSpatter(pos, mat, matg, state, amount)``
2494+
2495+
Adds a material spatter to the specified map tile. If the tile is already
2496+
full of that spatter, returns the amount left over.
2497+
2498+
Specifying a state of -1 (None) will automatically choose either Solid,
2499+
Liquid, or Gas based on the material properties and the tile temperature.
2500+
2501+
* ``dfhack.maps.addItemSpatter(pos, i_type, i_subtype, subcat1, subcat2, print_variant, amount)``
2502+
2503+
Adds an item spatter to the specified map tile. If the tile is already
2504+
full of that spatter, returns the amount left over.
2505+
2506+
For plant growths, specifying a print_variant of -1 will automatically
2507+
choose an appropriate value. For other item types, this field is ignored.
2508+
24892509
Burrows module
24902510
--------------
24912511

library/LuaApi.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ distribution.
9292
#include "df/job_item.h"
9393
#include "df/job_material_category.h"
9494
#include "df/language_word_table.h"
95+
#include "df/manager_order.h"
9596
#include "df/material.h"
9697
#include "df/map_block.h"
9798
#include "df/nemesis_record.h"
@@ -2018,6 +2019,7 @@ static const LuaWrapper::FunctionReg dfhack_job_module[] = {
20182019
WRAPM(Job,isSuitableItem),
20192020
WRAPM(Job,isSuitableMaterial),
20202021
WRAPM(Job,getName),
2022+
WRAPM(Job,getManagerOrderName),
20212023
WRAPM(Job,linkIntoWorld),
20222024
WRAPM(Job,removePostings),
20232025
WRAPM(Job,disconnectJobItem),
@@ -2781,6 +2783,40 @@ static int maps_removeTileAquifer(lua_State* L)
27812783
return 1;
27822784
}
27832785

2786+
static int maps_addMaterialSpatter(lua_State *L)
2787+
{
2788+
int32_t rv;
2789+
df::coord pos;
2790+
2791+
Lua::CheckDFAssign(L, &pos, 1);
2792+
int16_t mat = lua_tointeger(L, 2);
2793+
int32_t matg = lua_tointeger(L, 3);
2794+
df::matter_state state = (df::matter_state)lua_tointeger(L, 4);
2795+
int32_t amount = lua_tointeger(L, 5);
2796+
rv = Maps::addMaterialSpatter(pos, mat, matg, state, amount);
2797+
2798+
lua_pushinteger(L, rv);
2799+
return 1;
2800+
}
2801+
2802+
static int maps_addItemSpatter(lua_State *L)
2803+
{
2804+
int32_t rv;
2805+
df::coord pos;
2806+
2807+
Lua::CheckDFAssign(L, &pos, 1);
2808+
df::item_type i_type = (df::item_type)lua_tointeger(L, 2);
2809+
int16_t i_subtype = lua_tointeger(L, 3);
2810+
int16_t i_subcat1 = lua_tointeger(L, 4);
2811+
int32_t i_subcat2 = lua_tointeger(L, 5);
2812+
int32_t print_variant = lua_tointeger(L, 6);
2813+
int32_t amount = lua_tointeger(L, 7);
2814+
rv = Maps::addItemSpatter(pos, i_type, i_subtype, i_subcat1, i_subcat2, print_variant, amount);
2815+
2816+
lua_pushinteger(L, rv);
2817+
return 1;
2818+
}
2819+
27842820
static const luaL_Reg dfhack_maps_funcs[] = {
27852821
{ "isValidTilePos", maps_isValidTilePos },
27862822
{ "isTileVisible", maps_isTileVisible },
@@ -2796,6 +2832,8 @@ static const luaL_Reg dfhack_maps_funcs[] = {
27962832
{ "isTileHeavyAquifer", maps_isTileHeavyAquifer },
27972833
{ "setTileAquifer", maps_setTileAquifer },
27982834
{ "removeTileAquifer", maps_removeTileAquifer },
2835+
{ "addMaterialSpatter", maps_addMaterialSpatter },
2836+
{ "addItemSpatter", maps_addItemSpatter },
27992837
{ NULL, NULL }
28002838
};
28012839

library/include/modules/Items.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ DFHACK_EXPORT int getItemBaseValue(int16_t item_type, int16_t item_subtype, int1
170170
// Gets the value of a specific item, taking into account civ values and trade agreements if a caravan is given.
171171
DFHACK_EXPORT int getValue(df::item *item, df::caravan_state *caravan = NULL);
172172

173+
// Automatically choose a growth print variant for the specified plant growth subtype+material
174+
DFHACK_EXPORT int32_t pickGrowthPrint(int16_t subtype, int16_t mat, int32_t matg);
175+
173176
DFHACK_EXPORT bool createItem(std::vector<df::item *> &out_items, df::unit *creator, df::item_type type,
174177
int16_t item_subtype, int16_t mat_type, int32_t mat_index, bool no_floor = false, int32_t count = 1);
175178

@@ -186,6 +189,9 @@ DFHACK_EXPORT bool markForTrade(df::item *item, df::building_tradedepotst *depot
186189
// Returns true if an active caravan will pay extra for the given item.
187190
DFHACK_EXPORT bool isRequestedTradeGood(df::item *item, df::caravan_state *caravan = NULL);
188191

192+
// DF standard_material_itemtype - returns true if item has material/matgloss, false if race+caste
193+
DFHACK_EXPORT bool usesStandardMaterial(df::item_type item_type);
194+
189195
// Returns true if the item can currently be melted. If game_ui, then able to be marked is enough.
190196
DFHACK_EXPORT bool canMelt(df::item *item, bool game_ui = false);
191197
// Marks the item for melting.

library/include/modules/Job.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ namespace df
4141
struct job_item_filter;
4242
struct building;
4343
struct unit;
44+
struct manager_order;
4445
}
4546

4647
namespace DFHack
@@ -117,6 +118,7 @@ namespace DFHack
117118
int mat_index,
118119
df::item_type itype);
119120
DFHACK_EXPORT std::string getName(df::job *job);
121+
DFHACK_EXPORT std::string getManagerOrderName(df::manager_order *order);
120122

121123
struct JobDeleter {
122124
void operator()(df::job *ptr) const {

library/include/modules/Maps.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ distribution.
3838
#include "df/block_flags.h"
3939
#include "df/feature_type.h"
4040
#include "df/flow_type.h"
41+
#include "df/matter_state.h"
4142
#include "df/tile_dig_designation.h"
4243
#include "df/tiletype.h"
4344

@@ -372,6 +373,10 @@ extern DFHACK_EXPORT bool SortBlockEvents(df::map_block *block,
372373
std::vector<df::block_square_event_designation_priorityst *> *priorities = 0
373374
);
374375

376+
// Add spatters at the specified location, returning the amount that couldn't be placed (e.g. due to overflow)
377+
extern DFHACK_EXPORT int32_t addMaterialSpatter (df::coord pos, int16_t mat, int32_t matg, df::matter_state state, int32_t amount);
378+
extern DFHACK_EXPORT int32_t addItemSpatter (df::coord pos, df::item_type i_type, int16_t i_subtype, int16_t i_subcat1, int32_t i_subcat2, int32_t print_variant, int32_t amount);
379+
375380
// Remove a block event from the block by address.
376381
extern DFHACK_EXPORT bool RemoveBlockEvent(int32_t x, int32_t y, int32_t z, df::block_square_event *which );
377382
extern DFHACK_EXPORT bool RemoveBlockEvent(uint32_t x, uint32_t y, uint32_t z, df::block_square_event *which ); // TODO: deprecate me

library/modules/Items.cpp

Lines changed: 48 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1752,6 +1752,37 @@ int Items::getValue(df::item *item, df::caravan_state *caravan) {
17521752
return value;
17531753
}
17541754

1755+
// Automatically choose a growth print variant for the specified plant growth subtype+material
1756+
int32_t Items::pickGrowthPrint(int16_t subtype, int16_t mat, int32_t matg)
1757+
{
1758+
int growth_print = -1;
1759+
// Make sure it's made of a valid plant material, then grab its definition
1760+
if (mat >= 419 && mat <= 618 && matg >= 0 && (unsigned)matg < world->raws.plants.all.size())
1761+
{
1762+
auto plant_def = world->raws.plants.all[matg];
1763+
// Make sure it subtype is also valid
1764+
if (subtype >= 0 && (unsigned)subtype < plant_def->growths.size())
1765+
{
1766+
auto growth_def = plant_def->growths[subtype];
1767+
// Try and find a growth print matching the current time
1768+
// (in practice, only tree leaves use this for autumn color changes)
1769+
for (size_t i = 0; i < growth_def->prints.size(); i++)
1770+
{
1771+
auto print_def = growth_def->prints[i];
1772+
if (print_def->timing_start <= *df::global::cur_year_tick && *df::global::cur_year_tick <= print_def->timing_end)
1773+
{
1774+
growth_print = i;
1775+
break;
1776+
}
1777+
}
1778+
// If we didn't find one, then pick the first one (if it exists)
1779+
if (growth_print == -1 && !growth_def->prints.empty())
1780+
growth_print = 0;
1781+
}
1782+
}
1783+
return growth_print;
1784+
}
1785+
17551786
bool Items::createItem(vector<df::item *> &out_items, df::unit *unit, df::item_type item_type,
17561787
int16_t item_subtype, int16_t mat_type, int32_t mat_index, bool no_floor, int32_t count)
17571788
{ // Based on Quietust's plugins/createitem.cpp
@@ -1802,34 +1833,7 @@ bool Items::createItem(vector<df::item *> &out_items, df::unit *unit, df::item_t
18021833
for (auto out_item : out_items)
18031834
{ // Plant growths need a valid "growth print", otherwise they behave oddly
18041835
if (auto growth = virtual_cast<df::item_plant_growthst>(out_item))
1805-
{
1806-
int growth_print = -1;
1807-
// Make sure it's made of a valid plant material, then grab its definition
1808-
if (growth->mat_type >= 419 && growth->mat_type <= 618 && growth->mat_index >= 0 && (unsigned)growth->mat_index < world->raws.plants.all.size())
1809-
{
1810-
auto plant_def = world->raws.plants.all[growth->mat_index];
1811-
// Make sure it subtype is also valid
1812-
if (growth->subtype >= 0 && (unsigned)growth->subtype < plant_def->growths.size())
1813-
{
1814-
auto growth_def = plant_def->growths[growth->subtype];
1815-
// Try and find a growth print matching the current time
1816-
// (in practice, only tree leaves use this for autumn color changes)
1817-
for (size_t i = 0; i < growth_def->prints.size(); i++)
1818-
{
1819-
auto print_def = growth_def->prints[i];
1820-
if (print_def->timing_start <= *df::global::cur_year_tick && *df::global::cur_year_tick <= print_def->timing_end)
1821-
{
1822-
growth_print = i;
1823-
break;
1824-
}
1825-
}
1826-
// If we didn't find one, then pick the first one (if it exists)
1827-
if (growth_print == -1 && !growth_def->prints.empty())
1828-
growth_print = 0;
1829-
}
1830-
}
1831-
growth->growth_print = growth_print;
1832-
}
1836+
growth->growth_print = pickGrowthPrint(growth->subtype, growth->mat_type, growth->mat_index);
18331837
if (!no_floor)
18341838
out_item->moveToGround(pos.x, pos.y, pos.z);
18351839
}
@@ -1962,17 +1966,10 @@ bool Items::isRequestedTradeGood(df::item *item, df::caravan_state *caravan) {
19621966
return false;
19631967
}
19641968

1965-
/// When called with game_ui = true, this is equivalent to Bay12's itemst::meltable()
1966-
/// (i.e., returning true if and only if the item has a "designate for melting" button in game)
1967-
bool Items::canMelt(df::item *item, bool game_ui) {
1968-
CHECK_NULL_POINTER(item);
1969-
MaterialInfo mat(item);
1970-
if (mat.getCraftClass() != craft_material_class::Metal)
1971-
return false;
1972-
1973-
switch(item->getType())
1969+
bool Items::usesStandardMaterial(df::item_type item_type)
1970+
{
1971+
switch(item_type)
19741972
{ using namespace df::enums::item_type;
1975-
// These are not meltable, even if made from metal
19761973
case CORPSE:
19771974
case CORPSEPIECE:
19781975
case REMAINS:
@@ -1984,8 +1981,20 @@ bool Items::canMelt(df::item *item, bool game_ui) {
19841981
case EGG:
19851982
return false;
19861983
default:
1987-
break;
1984+
return true;
19881985
}
1986+
}
1987+
1988+
/// When called with game_ui = true, this is equivalent to Bay12's itemst::meltable()
1989+
/// (i.e., returning true if and only if the item has a "designate for melting" button in game)
1990+
bool Items::canMelt(df::item *item, bool game_ui) {
1991+
CHECK_NULL_POINTER(item);
1992+
MaterialInfo mat(item);
1993+
if (mat.getCraftClass() != craft_material_class::Metal)
1994+
return false;
1995+
1996+
if (!usesStandardMaterial(item->getType()))
1997+
return false;
19891998

19901999
if (item->flags.bits.artifact)
19912000
return false;

library/modules/Job.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ distribution.
4949
#include "df/job_list_link.h"
5050
#include "df/job_postingst.h"
5151
#include "df/job_restrictionst.h"
52+
#include "df/manager_order.h"
5253
#include "df/plotinfost.h"
5354
#include "df/specific_ref.h"
5455
#include "df/unit.h"
@@ -686,3 +687,27 @@ std::string Job::getName(df::job *job)
686687

687688
return desc;
688689
}
690+
691+
std::string Job::getManagerOrderName(df::manager_order *order)
692+
{
693+
CHECK_NULL_POINTER(order);
694+
695+
std::string desc;
696+
auto button = df::allocate<df::interface_button_building_new_jobst>();
697+
button->mstring = order->reaction_name;
698+
button->jobtype = order->job_type;
699+
button->itemtype = order->item_type;
700+
button->subtype = order->item_subtype;
701+
button->material = order->mat_type;
702+
button->matgloss = order->mat_index;
703+
button->specflag = order->specflag;
704+
button->job_item_flag = order->material_category;
705+
button->specdata = order->specdata;
706+
button->art_specifier_id1 = order->art_spec.id;
707+
button->art_specifier_id2 = order->art_spec.subid;
708+
709+
button->text(&desc);
710+
delete button;
711+
712+
return desc;
713+
}

0 commit comments

Comments
 (0)