Skip to content

Commit bce5c0b

Browse files
committed
Merge remote-tracking branches 'AtomicChicken/bodyswap' and 'AtomicChicken/create-unit'
2 parents d747dda + 9a92e1d commit bce5c0b

19 files changed

Lines changed: 750 additions & 214 deletions

adv-rumors.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,20 @@ adv-rumors
66
==========
77
Improves the "Bring up specific incident or rumor" menu in Adventure mode.
88
9+
- Moves entries into one line
10+
- Adds a "slew" keyword for filtering, making it easy to find your kills and not your companions'
11+
- Trims repetitive words
12+
913
]====]
1014

1115
--========================
1216
-- Author : 1337G4mer on bay12 and reddit
1317
-- Version : 0.2
1418
-- Description : A small utility based on dfhack to improve the rumor UI in adventure mode.
1519
--
16-
-- Usage: Save this code as rumors.lua file in your /hack/scripts/ folder
1720
-- In game when you want to boast about your kill to someone. Start conversation and choose
1821
-- the menu "Bring up specific incident or rumor"
1922
-- type rumors in dfhack window and hit enter. Or do the below keybind and use that directly from DF window.
20-
-- Optional One time setup : run below command at dfhack command prompt once to setup easy keybind for this
21-
-- keybinding add Ctrl-A@dungeonmode/ConversationSpeak rumors
2223
--
2324
-- Prior Configuration: (you can skip this if you want)
2425
-- Set the three boolean values below and play around with the script as to how you like

caravan.lua

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
-- Adjusts properties of caravans
2+
--[====[
3+
4+
caravan
5+
=======
6+
7+
Adjusts properties of caravans on the map. See also `force` to create caravans.
8+
9+
This script has multiple subcommands. Commands listed with the argument
10+
``[IDS]`` can take multiple caravan IDs (see ``caravan list``). If no IDs are
11+
specified, then the commands apply to all caravans on the map.
12+
13+
**Subcommands:**
14+
15+
- ``list``: lists IDs and information about all caravans on the map.
16+
- ``extend [DAYS] [IDS]``: extends the time that caravans stay at the depot by
17+
the specified number of days (defaults to 7 if not specified). Also causes
18+
caravans to return to the depot if applicable.
19+
- ``happy [IDS]``: makes caravans willing to trade again (after seizing goods,
20+
annoying merchants, etc.). Also causes caravans to return to the depot if
21+
applicable.
22+
- ``leave [IDS]``: makes caravans pack up and leave immediately.
23+
24+
]====]
25+
26+
--@ module = true
27+
28+
INTERESTING_FLAGS = {
29+
casualty = 'Casualty',
30+
hardship = 'Encountered hardship',
31+
seized = 'Goods seized',
32+
offended = 'Offended'
33+
}
34+
caravans = df.global.ui.caravans
35+
36+
function caravans_from_ids(ids)
37+
if not ids or #ids == 0 then
38+
return pairs(caravans)
39+
end
40+
local i = 0
41+
return function()
42+
i = i + 1
43+
local id = tonumber(ids[i])
44+
if id then
45+
return id, caravans[id]
46+
end
47+
return nil
48+
end
49+
end
50+
51+
function bring_back(car)
52+
if car.trade_state ~= df.caravan_state.T_trade_state.AtDepot then
53+
car.trade_state = df.caravan_state.T_trade_state.Approaching
54+
end
55+
end
56+
57+
commands = {}
58+
59+
function commands.list()
60+
for id, car in pairs(caravans) do
61+
print(dfhack.df2console(('%d: %s caravan from %s'):format(
62+
id,
63+
df.creature_raw.find(df.historical_entity.find(car.entity).race).name[2], -- adjective
64+
dfhack.TranslateName(df.historical_entity.find(car.entity).name)
65+
)))
66+
print(' ' .. (df.caravan_state.T_trade_state[car.trade_state] or 'Unknown state: ' .. car.trade_state))
67+
print((' %d day(s) remaining'):format(math.floor(car.time_remaining / 120)))
68+
for flag, msg in pairs(INTERESTING_FLAGS) do
69+
if car.flags[flag] then
70+
print(' ' .. msg)
71+
end
72+
end
73+
end
74+
end
75+
76+
function commands.extend(days, ...)
77+
days = tonumber(days or 7) or qerror('invalid number of days: ' .. days)
78+
for id, car in caravans_from_ids{...} do
79+
car.time_remaining = car.time_remaining + (days * 120)
80+
bring_back(car)
81+
end
82+
end
83+
84+
function commands.happy(...)
85+
for id, car in caravans_from_ids{...} do
86+
-- all flags default to false
87+
car.flags.whole = 0
88+
bring_back(car)
89+
end
90+
end
91+
92+
function commands.leave(...)
93+
for id, car in caravans_from_ids{...} do
94+
car.trade_state = df.caravan_state.T_trade_state.Leaving
95+
end
96+
end
97+
98+
function main(...)
99+
args = {...}
100+
command = table.remove(args, 1)
101+
commands[command](table.unpack(args))
102+
end
103+
104+
if not dfhack_flags.module then
105+
main(...)
106+
end

devel/export-dt-ini.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ address('sub_type',df.itemdef,'subtype')
229229
address('name',df.itemdef_armorst,'name')
230230
address('name_plural',df.itemdef_armorst,'name_plural')
231231
address('adjective',df.itemdef_armorst,'name_preplural')
232+
address('tool_flags',df.itemdef_toolst,'flags')
233+
address('tool_adjective',df.itemdef_toolst,'adjective')
232234

233235
header('item_filter_offsets')
234236
address('item_subtype',df.item_filter_spec,'item_subtype')

devel/find-primitive.lua

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
-- Finds a primitive variable in memory
2+
3+
--[====[
4+
5+
devel/find-primitive
6+
====================
7+
8+
Finds a primitive variable in DF's data section, relying on the user to change
9+
its value. This is similar to `devel/find-offsets`, but useful for new variables
10+
whose locations are unknown (i.e. they could be part of an existing global).
11+
12+
Usage::
13+
14+
devel/find-primitive data-type val1 val2 [val3...]
15+
16+
where ``data-type`` is a primitive type (int32_t, uint8_t, long, etc.) and each
17+
``val`` is a valid value for that type.
18+
19+
Use ``devel/find-primitive help`` for a list of valid data types.
20+
21+
]====]
22+
23+
ms = require('memscan')
24+
25+
searcher = ms.DiffSearcher.new(ms.get_data_segment())
26+
values = {...}
27+
data_type = table.remove(values, 1)
28+
29+
function is_valid_data_type(t)
30+
return getmetatable(searcher.area[t]) == ms.CheckedArray
31+
end
32+
33+
if data_type == 'help' or not is_valid_data_type(data_type) then
34+
print('Valid data types:')
35+
for t in pairs(searcher.area) do
36+
if is_valid_data_type(t) then
37+
print(' ' .. t)
38+
end
39+
end
40+
if data_type ~= 'help' then
41+
qerror('Invalid data type')
42+
end
43+
return
44+
end
45+
46+
addr = searcher:find_menu_cursor(
47+
'Adjust the value of the variable so that it matches the message given, then press enter.',
48+
data_type,
49+
values
50+
)
51+
if addr then
52+
print(('0x%x'):format(addr))
53+
else
54+
qerror('Unable to find variable')
55+
end

devel/save-version.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ versions = {
9898
[1604] = "0.44.05",
9999
[1611] = "0.44.06",
100100
[1612] = "0.44.07",
101+
[1613] = "0.44.08",
102+
[1614] = "0.44.09",
103+
[1620] = "0.44.10",
101104
}
102105

103106
min_version = math.huge
@@ -134,7 +137,7 @@ end
134137

135138
function describe(version)
136139
if version == 0 then
137-
return 'no world loaded'
140+
return 'not saved'
138141
elseif versions[version] then
139142
return versions[version] .. (' (%i)'):format(version)
140143
elseif version < min_version then
@@ -159,4 +162,5 @@ if not moduleMode then
159162
if not dfhack.isWorldLoaded() then qerror('no world loaded') end
160163
dump('original DF version', get_original_save_version)
161164
dump('most recent DF version', get_save_version)
165+
dump('running DF version', function() return df.global.version end)
162166
end

exterminate.rb

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
88
With no argument, lists the available races and count eligible targets.
99
10-
With the special argument ``him``, targets only the selected creature.
10+
With the special argument ``this``, targets only the selected creature.
11+
Alternatively, ``him``, ``her``, ``it``, ``target``, and ``selected``
12+
do the same thing.
1113
1214
With the special argument ``undead``, targets all undeads on the map,
1315
regardless of their race.
@@ -35,7 +37,7 @@
3537
3638
To kill a single creature, select the unit with the 'v' cursor and::
3739
38-
exterminate him
40+
exterminate this
3941
4042
To purify all elves on the map with fire (may have side-effects)::
4143
@@ -116,7 +118,8 @@
116118
puts <<EOS
117119
Kills all creatures of a given race.
118120
With no argument, lists possible targets with their head count.
119-
With the special argument 'him' or 'her', kill only the currently selected creature.
121+
With the special argument 'this', kill only the currently selected creature.
122+
Alternatively, 'him', 'her', 'it', 'target', and 'selected' do the same thing.
120123
With the special argument 'undead', kill all undead creatures/thralls.
121124
122125
The targets will bleed out on the next game tick, or if they are immune to that, will vanish in a puff of smoke.
@@ -131,13 +134,8 @@
131134
exterminate pig butcher
132135
EOS
133136

134-
when 'him', 'her', 'it', 'that'
137+
when 'him', 'her', 'it', 'that', 'this', 'selected', 'target'
135138
if him = df.unit_find
136-
case him.race_tg.caste[him.caste].gender
137-
when 0; puts 'its a she !' if race != 'her'
138-
when 1; puts 'its a he !' if race != 'him'
139-
else; puts 'its an it !' if race != 'it' and race != 'that'
140-
end
141139
slayit[him]
142140
else
143141
puts "Select a target ingame"

fillneeds.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ local utils = require('utils')
1414
local args = utils.processArgs({...})
1515

1616
function satisfyNeeds(unit)
17+
if not unit.status.current_soul then
18+
return
19+
end
1720
local mind = unit.status.current_soul.personality.needs
1821
for k,v in ipairs(mind) do
1922
mind[k].focus_level = 400

fix/dead-units.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ for i=#units-1,0,-1 do
1717
local unit = units[i]
1818
local flags1 = unit.flags1
1919
local flags2 = unit.flags2
20-
if flags1.dead and unit.race ~= dwarf_race then
20+
if flags1.dead and flags2.killed and unit.race ~= dwarf_race then
2121
local remove = false
2222
if flags2.slaughter then
2323
remove = true

0 commit comments

Comments
 (0)