Skip to content

Commit 3113f73

Browse files
authored
Merge branch 'master' into create-unit
2 parents f81ba57 + a1cd002 commit 3113f73

8 files changed

Lines changed: 472 additions & 65 deletions

File tree

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/save-version.lua

Lines changed: 3 additions & 0 deletions
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

exterminate.rb

Lines changed: 5 additions & 8 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``, ``this``, ``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
@@ -131,13 +133,8 @@
131133
exterminate pig butcher
132134
EOS
133135

134-
when 'him', 'her', 'it', 'that'
136+
when 'him', 'her', 'it', 'that', 'this', 'selected', 'target'
135137
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
141138
slayit[him]
142139
else
143140
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)