Skip to content

Commit

Permalink
Merge pull request #1319 from myk002/myk_force
Browse files Browse the repository at this point in the history
[force] support "Wildlife" synthetic event
  • Loading branch information
myk002 authored Oct 4, 2024
2 parents 7a2ffc5 + 20cc47b commit b5a941f
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 114 deletions.
2 changes: 2 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Template for new versions:
- `fix/wildlife`: prevent wildlife from getting stuck when trying to exit the map. This fix needs to be enabled manually in `gui/control-panel` on the Bug Fixes tab since not all players want this bug to be fixed.

## 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 All @@ -42,6 +43,7 @@ Template for new versions:
- `fix/stuck-worship`: reduced console output by default. Added ``--verbose`` and ``--quiet`` options.

## Removed
- `modtools/force`: merged into `force`

# 50.13-r5

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 100
ticks to take effect.
32 changes: 0 additions & 32 deletions docs/modtools/force.rst

This file was deleted.

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,
})
64 changes: 0 additions & 64 deletions modtools/force.lua

This file was deleted.

0 comments on commit b5a941f

Please sign in to comment.