Skip to content

Commit ef69522

Browse files
committed
Merge branch 'develop' into filesystem-module-pr
2 parents 6fa478d + 9580aa6 commit ef69522

File tree

15 files changed

+992
-168
lines changed

15 files changed

+992
-168
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ DFHack future
44
- support for calling a lua function via a protobuf request (demonstrated by dfhack-run --lua).
55
- Lua API for listing files in directory. Needed for mod-manager.
66
- Lua API for creating unit combat reports and writing to gamelog.
7+
- Lua API for running arbitrary DFHack commands
78
- support for multiple raw/init.d/*.lua init scripts in one save.
89
- eventful now has a more friendly way of making custom sidebars
910
- new plugin: building-hacks. Allows to add custom functionality and/or animations to buildings.
@@ -26,10 +27,12 @@ DFHack future
2627
New tweaks:
2728
- craft-age-wear: make crafted items wear out with time like in old versions (bug 6003)
2829
- adamantine-cloth-wear: stop adamantine clothing from wearing out (bug 6481)
30+
- confirm-embark: adds a prompt before embarking (on the "prepare carefully" screen)
2931

3032
New plugins:
3133
- rendermax: replace the renderer with something else. Most interesting is "rendermax light"- a lighting engine for df.
3234
- stockflow (by eswald): queues manager jobs of the configured type based on the state of a stockpile.
35+
- embark-tools: implementations of Embark Anywhere, Nano Embark, and a few other embark-related utilities
3336

3437
Misc improvements:
3538
- digfort: improved csv parsing, add start() comment handling

Readme.html

Lines changed: 148 additions & 130 deletions
Large diffs are not rendered by default.

Readme.rst

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2053,6 +2053,21 @@ See the bay12 thread for details: http://www.bay12forums.com/smf/index.php?topic
20532053
* Some of the DFusion plugins aren't completely ported yet. This can lead to crashes.
20542054
* The game will be suspended while you're using dfusion. Don't panic when it doesn't respond.
20552055

2056+
embark-tools
2057+
------------
2058+
A collection of embark-related tools.
2059+
2060+
Usage::
2061+
2062+
embark-tools enable/disable tool [tool]...
2063+
2064+
Tools:
2065+
2066+
* ``anywhere``: Allows embarking anywhere (including sites, mountain-only biomes, and oceans). Use with caution.
2067+
* ``nano``: An implementation of nano embark - allows resizing below 2x2 when enabled.
2068+
* ``sand``: Displays an indicator when sand is present in the currently-selected area, similar to the default clay/stone indicators.
2069+
* ``sticky``: Maintains the selected local area while navigating the world map
2070+
20562071
misery
20572072
------
20582073
When enabled, every new negative dwarven thought will be multiplied by a factor (2 by default).
@@ -2523,15 +2538,19 @@ To activate, open the unit screen and press 'l'.
25232538

25242539
This tool implements a Dwarf Therapist-like interface within the game UI. The
25252540
far left column displays the unit's Happiness (color-coded based on its
2526-
value), and the right half of the screen displays each dwarf's labor settings
2527-
and skill levels (0-9 for Dabbling thru Professional, A-E for Great thru Grand
2528-
Master, and U-Z for Legendary thru Legendary+5).
2541+
value), Name, Profession/Squad, and the right half of the screen displays each
2542+
dwarf's labor settings and skill levels (0-9 for Dabbling thru Professional, A-E for
2543+
Great thru Grand Master, and U-Z for Legendary thru Legendary+5).
25292544

25302545
Cells with teal backgrounds denote skills not controlled by labors, e.g.
25312546
military and social skills.
25322547

25332548
.. image:: images/manipulator2.png
25342549

2550+
Press ``t`` to toggle between Profession and Squad view.
2551+
2552+
.. image:: images/manipulator3.png
2553+
25352554
Use the arrow keys or number pad to move the cursor around, holding Shift to
25362555
move 10 tiles at a time.
25372556

@@ -2543,7 +2562,7 @@ Press Enter to toggle the selected labor for the selected unit, or Shift+Enter
25432562
to toggle all labors within the selected category.
25442563

25452564
Press the ``+-`` keys to sort the unit list according to the currently selected
2546-
skill/labor, and press the ``*/`` keys to sort the unit list by Name, Profession,
2565+
skill/labor, and press the ``*/`` keys to sort the unit list by Name, Profession/Squad,
25472566
Happiness, or Arrival order (using Tab to select which sort method to use here).
25482567

25492568
With a unit selected, you can press the "v" key to view its properties (and
@@ -2553,12 +2572,12 @@ Manipulator and zoom to its position within your fortress.
25532572
The following mouse shortcuts are also available:
25542573

25552574
* Click on a column header to sort the unit list. Left-click to sort it in one
2556-
direction (descending for happiness or labors/skills, ascending for name or
2557-
profession) and right-click to sort it in the opposite direction.
2575+
direction (descending for happiness or labors/skills, ascending for name,
2576+
profession or squad) and right-click to sort it in the opposite direction.
25582577
* Left-click on a labor cell to toggle that labor. Right-click to move the
25592578
cursor onto that cell instead of toggling it.
2560-
* Left-click on a unit's name or profession to view its properties.
2561-
* Right-click on a unit's name or profession to zoom to it.
2579+
* Left-click on a unit's name, profession or squad to view its properties.
2580+
* Right-click on a unit's name, profession or squad to zoom to it.
25622581

25632582
Pressing ESC normally returns to the unit screen, but Shift-ESC would exit
25642583
directly to the main dwarf mode screen.

images/manipulator.png

-1.01 KB
Loading

images/manipulator2.png

119 Bytes
Loading

images/manipulator3.png

8.3 KB
Loading

library/LuaApi.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2242,6 +2242,64 @@ static int internal_getDir(lua_State *L)
22422242
}
22432243
return 1;
22442244
}
2245+
2246+
static int internal_runCommand(lua_State *L)
2247+
{
2248+
buffered_color_ostream out;
2249+
command_result res;
2250+
if (lua_gettop(L) == 0)
2251+
{
2252+
lua_pushstring(L, "");
2253+
}
2254+
int type_1 = lua_type(L, 1);
2255+
if (type_1 == LUA_TTABLE)
2256+
{
2257+
std::string command = "";
2258+
std::vector<std::string> args;
2259+
lua_pushnil(L); // first key
2260+
while (lua_next(L, 1) != 0)
2261+
{
2262+
if (command == "")
2263+
command = lua_tostring(L, -1);
2264+
else
2265+
args.push_back(lua_tostring(L, -1));
2266+
lua_pop(L, 1); // remove value, leave key
2267+
}
2268+
CoreSuspender suspend;
2269+
res = Core::getInstance().runCommand(out, command, args);
2270+
}
2271+
else if (type_1 == LUA_TSTRING)
2272+
{
2273+
std::string command = lua_tostring(L, 1);
2274+
CoreSuspender suspend;
2275+
res = Core::getInstance().runCommand(out, command);
2276+
}
2277+
else
2278+
{
2279+
lua_pushnil(L);
2280+
lua_pushfstring(L, "Expected table, got %s", lua_typename(L, type_1));
2281+
return 2;
2282+
}
2283+
auto fragments = out.fragments();
2284+
lua_newtable(L);
2285+
lua_pushinteger(L, (int)res);
2286+
lua_setfield(L, -2, "status");
2287+
int i = 1;
2288+
for (auto iter = fragments.begin(); iter != fragments.end(); iter++, i++)
2289+
{
2290+
int color = iter->first;
2291+
std::string output = iter->second;
2292+
lua_createtable(L, 2, 0);
2293+
lua_pushinteger(L, color);
2294+
lua_rawseti(L, -2, 1);
2295+
lua_pushstring(L, output.c_str());
2296+
lua_rawseti(L, -2, 2);
2297+
lua_rawseti(L, -2, i);
2298+
}
2299+
lua_pushvalue(L, -1);
2300+
return 1;
2301+
}
2302+
22452303
static const luaL_Reg dfhack_internal_funcs[] = {
22462304
{ "getAddress", internal_getAddress },
22472305
{ "setAddress", internal_setAddress },
@@ -2255,6 +2313,7 @@ static const luaL_Reg dfhack_internal_funcs[] = {
22552313
{ "memscan", internal_memscan },
22562314
{ "diffscan", internal_diffscan },
22572315
{ "getDir", internal_getDir },
2316+
{ "runCommand", internal_runCommand },
22582317
{ NULL, NULL }
22592318
};
22602319

library/include/modules/Units.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,8 @@ DFHACK_EXPORT std::string getCasteProfessionName(int race, int caste, df::profes
256256

257257
DFHACK_EXPORT int8_t getProfessionColor(df::unit *unit, bool ignore_noble = false);
258258
DFHACK_EXPORT int8_t getCasteProfessionColor(int race, int caste, df::profession pid);
259+
260+
DFHACK_EXPORT std::string getSquadName(df::unit *unit);
259261
}
260262
}
261263
#endif

library/lua/dfhack.lua

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ local dfhack = dfhack
1010
local base_env = dfhack.BASE_G
1111
local _ENV = base_env
1212

13+
CR_LINK_FAILURE = -3
14+
CR_NEEDS_CONSOLE = -2
15+
CR_NOT_IMPLEMENTED = -1
16+
CR_OK = 0
17+
CR_FAILURE = 1
18+
CR_WRONG_USAGE = 2
19+
CR_NOT_FOUND = 3
20+
1321
-- Console color constants
1422

1523
COLOR_RESET = -1
@@ -256,7 +264,8 @@ function dfhack.interpreter(prompt,hfile,env)
256264
print("Shortcuts:\n"..
257265
" '= foo' => '_1,_2,... = foo'\n"..
258266
" '! foo' => 'print(foo)'\n"..
259-
"Both save the first result as '_'.")
267+
" '~ foo' => 'printall(foo)'\n"..
268+
"All of these save the first result as '_'.")
260269
print_banner = false
261270
end
262271

@@ -357,6 +366,31 @@ function dfhack.run_script(name,...)
357366
return f(...)
358367
end
359368

369+
function dfhack.run_command(...)
370+
args = {...}
371+
if type(args[1]) == 'table' then
372+
command = args[1]
373+
elseif #args > 1 and type(args[2]) == 'table' then
374+
-- {args[1]} + args[2]
375+
command = args[2]
376+
table.insert(command, 1, args[1])
377+
elseif #args == 1 and type(args[1]) == 'string' then
378+
command = args[1]
379+
elseif #args > 1 and type(args[1]) == 'string' then
380+
command = args
381+
else
382+
error('Invalid arguments')
383+
end
384+
result = internal.runCommand(command)
385+
output = ""
386+
for i, f in pairs(result) do
387+
if type(f) == 'table' then
388+
output = output .. f[2]
389+
end
390+
end
391+
return output, result.status
392+
end
393+
360394
-- Per-save init file
361395

362396
function dfhack.getSavePath()

library/modules/Units.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ using namespace std;
6969
#include "df/unit_misc_trait.h"
7070
#include "df/unit_skill.h"
7171
#include "df/curse_attr_change.h"
72+
#include "df/squad.h"
7273

7374
using namespace DFHack;
7475
using namespace df::enums;
@@ -1552,3 +1553,15 @@ int8_t DFHack::Units::getCasteProfessionColor(int race, int casteid, df::profess
15521553
// default to dwarven peasant color
15531554
return 3;
15541555
}
1556+
1557+
std::string DFHack::Units::getSquadName(df::unit *unit)
1558+
{
1559+
if (unit->military.squad_id == -1)
1560+
return "";
1561+
df::squad *squad = df::squad::find(unit->military.squad_id);
1562+
if (!squad)
1563+
return "";
1564+
if (squad->alias.size() > 0)
1565+
return squad->alias;
1566+
return Translation::TranslateName(&squad->name, true);
1567+
}

0 commit comments

Comments
 (0)