Skip to content

Commit d698be4

Browse files
committed
support Wildlife synthetic "event"
merge modtools/force into force
1 parent dd9592c commit d698be4

3 files changed

Lines changed: 66 additions & 18 deletions

File tree

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Template for new versions:
2929
## New Tools
3030

3131
## New Features
32+
- `force`: support the ``Wildlife`` event to allow additional wildlife to enter the map
3233

3334
## Fixes
3435
- `gui/quickfort`: only print a help blueprint's text once even if the repeat setting is enabled

docs/force.rst

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Usage
1515
::
1616

1717
force <event> [<civ id>]
18+
force Wildlife [all]
1819

1920
The civ id is only used for ``Diplomat`` and ``Caravan`` events, and defaults
2021
to the player civilization if not specified.
@@ -27,18 +28,36 @@ The default civ IDs that you are likely to be interested in are:
2728

2829
But to see IDs for all civilizations in your current game, run this command::
2930

30-
devel/query --table df.global.world.entities.all --search code --maxdepth 2
31+
:lua ids={} for _,en in ipairs(world.entities.all) do ids[en.entity_raw.code] = true end for id in pairs(ids) do print(id) end
32+
33+
Examples
34+
--------
35+
36+
``force Caravan``
37+
Spawn a caravan from your parent civilization.
38+
``force Diplomat FOREST``
39+
Spawn an elven diplomat.
40+
``force Megabeast``
41+
Call in a megabeast to attack your fort. The megabeast will enter the map
42+
on the surface.
43+
``force Wildlife``
44+
Allow additional wildlife to enter the map. Only affects areas that you can
45+
see, so if you haven't opened the caverns, cavern wildlife won't be
46+
affected.
47+
``force Wildlife all``
48+
Allow additional wildlife to enter the map, even in areas you haven't
49+
explored yet.
3150

3251
Event types
3352
-----------
3453

35-
The recognized event types are:
54+
The supported event types are:
3655

3756
- ``Caravan``
3857
- ``Migrants``
3958
- ``Diplomat``
4059
- ``Megabeast``
41-
- ``WildlifeCurious``
42-
- ``WildlifeMischievous``
43-
- ``WildlifeFlier``
44-
- ``NightCreature``
60+
- ``Wildlife``
61+
62+
Most events happen on the next tick. The ``Wildlife`` event may take up to 14
63+
ticks to take effect.

force.lua

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,58 @@
1-
-- Forces an event (wrapper for modtools/force)
1+
local wildlife = reqscript('fix/wildlife')
22

3-
local utils = require 'utils'
4-
local args = {...}
3+
local function findCiv(civ)
4+
if civ == 'player' then return df.historical_entity.find(df.global.plotinfo.civ_id) end
5+
if tonumber(civ) then return df.historical_entity.find(tonumber(civ)) end
6+
civ = string.lower(tostring(civ))
7+
for _,entity in ipairs(df.global.world.entities.all) do
8+
if string.lower(entity.entity_raw.code) == civ then return entity end
9+
end
10+
end
11+
12+
local args = { ... }
513
if #args < 1 then qerror('missing event type') end
614
if args[1]:find('help') then
715
print(dfhack.script_help())
816
return
917
end
10-
local eventType = nil
18+
19+
local eventType = args[1]:upper()
20+
21+
-- handle synthetic events
22+
if eventType == 'WILDLIFE' then
23+
wildlife.free_all_wildlife(args[2] == 'all')
24+
return
25+
end
26+
27+
-- handle native events
1128
for _, type in ipairs(df.timed_event_type) do
1229
if type:lower() == args[1]:lower() then
1330
eventType = type
1431
end
1532
end
16-
if not eventType then
33+
if not df.timed_event_type[eventType] then
1734
qerror('unknown event type: ' .. args[1])
1835
end
36+
if eventType == 'FeatureAttack' then
37+
qerror('Event type: FeatureAttack is not currently supported')
38+
end
39+
40+
local civ
1941

20-
local newArgs = {'--eventType', eventType}
2142
if eventType == 'Caravan' or eventType == 'Diplomat' then
22-
table.insert(newArgs, '--civ')
23-
if not args[2] then
24-
table.insert(newArgs, 'player')
25-
else
26-
table.insert(newArgs, args[2])
43+
civ = findCiv(args[2] or 'player')
44+
if not civ then
45+
qerror('unable to find civilization: '..tostring(civ))
2746
end
47+
elseif eventType == 'Migrants' then
48+
civ = findCiv('player')
2849
end
2950

30-
dfhack.run_script('modtools/force', table.unpack(newArgs))
51+
df.global.timed_events:insert('#', {
52+
new=true,
53+
type=df.timed_event_type[eventType],
54+
season=df.global.cur_season,
55+
season_ticks=df.global.cur_season_tick,
56+
entity=civ,
57+
feature_ind=-1,
58+
})

0 commit comments

Comments
 (0)