Skip to content

Commit

Permalink
support Wildlife synthetic "event"
Browse files Browse the repository at this point in the history
merge modtools/force into force
  • Loading branch information
myk002 committed Oct 4, 2024
1 parent dd9592c commit d698be4
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 18 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Template for new versions:
## New Tools

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

## Fixes
- `gui/quickfort`: only print a help blueprint's text once even if the repeat setting is enabled
Expand Down
31 changes: 25 additions & 6 deletions docs/force.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Usage
::

force <event> [<civ id>]
force Wildlife [all]

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

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

devel/query --table df.global.world.entities.all --search code --maxdepth 2
: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

Examples
--------

``force Caravan``
Spawn a caravan from your parent civilization.
``force Diplomat FOREST``
Spawn an elven diplomat.
``force Megabeast``
Call in a megabeast to attack your fort. The megabeast will enter the map
on the surface.
``force Wildlife``
Allow additional wildlife to enter the map. Only affects areas that you can
see, so if you haven't opened the caverns, cavern wildlife won't be
affected.
``force Wildlife all``
Allow additional wildlife to enter the map, even in areas you haven't
explored yet.

Event types
-----------

The recognized event types are:
The supported event types are:

- ``Caravan``
- ``Migrants``
- ``Diplomat``
- ``Megabeast``
- ``WildlifeCurious``
- ``WildlifeMischievous``
- ``WildlifeFlier``
- ``NightCreature``
- ``Wildlife``

Most events happen on the next tick. The ``Wildlife`` event may take up to 14
ticks to take effect.
52 changes: 40 additions & 12 deletions force.lua
Original file line number Diff line number Diff line change
@@ -1,30 +1,58 @@
-- Forces an event (wrapper for modtools/force)
local wildlife = reqscript('fix/wildlife')

local utils = require 'utils'
local args = {...}
local function findCiv(civ)
if civ == 'player' then return df.historical_entity.find(df.global.plotinfo.civ_id) end
if tonumber(civ) then return df.historical_entity.find(tonumber(civ)) end
civ = string.lower(tostring(civ))
for _,entity in ipairs(df.global.world.entities.all) do
if string.lower(entity.entity_raw.code) == civ then return entity end
end
end

local args = { ... }
if #args < 1 then qerror('missing event type') end
if args[1]:find('help') then
print(dfhack.script_help())
return
end
local eventType = nil

local eventType = args[1]:upper()

-- handle synthetic events
if eventType == 'WILDLIFE' then
wildlife.free_all_wildlife(args[2] == 'all')
return
end

-- handle native events
for _, type in ipairs(df.timed_event_type) do
if type:lower() == args[1]:lower() then
eventType = type
end
end
if not eventType then
if not df.timed_event_type[eventType] then
qerror('unknown event type: ' .. args[1])
end
if eventType == 'FeatureAttack' then
qerror('Event type: FeatureAttack is not currently supported')
end

local civ

local newArgs = {'--eventType', eventType}
if eventType == 'Caravan' or eventType == 'Diplomat' then
table.insert(newArgs, '--civ')
if not args[2] then
table.insert(newArgs, 'player')
else
table.insert(newArgs, args[2])
civ = findCiv(args[2] or 'player')
if not civ then
qerror('unable to find civilization: '..tostring(civ))
end
elseif eventType == 'Migrants' then
civ = findCiv('player')
end

dfhack.run_script('modtools/force', table.unpack(newArgs))
df.global.timed_events:insert('#', {
new=true,
type=df.timed_event_type[eventType],
season=df.global.cur_season,
season_ticks=df.global.cur_season_tick,
entity=civ,
feature_ind=-1,
})

0 comments on commit d698be4

Please sign in to comment.