From d698be43ebaa3ccff7bfa3fb0537db915e8541c2 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Fri, 4 Oct 2024 16:04:05 -0700 Subject: [PATCH 1/4] support Wildlife synthetic "event" merge modtools/force into force --- changelog.txt | 1 + docs/force.rst | 31 ++++++++++++++++++++++++------ force.lua | 52 ++++++++++++++++++++++++++++++++++++++------------ 3 files changed, 66 insertions(+), 18 deletions(-) diff --git a/changelog.txt b/changelog.txt index b58d36042f..a2d46d6fa7 100644 --- a/changelog.txt +++ b/changelog.txt @@ -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 diff --git a/docs/force.rst b/docs/force.rst index 915863a75f..5bc13bd7f6 100644 --- a/docs/force.rst +++ b/docs/force.rst @@ -15,6 +15,7 @@ Usage :: force [] + force Wildlife [all] The civ id is only used for ``Diplomat`` and ``Caravan`` events, and defaults to the player civilization if not specified. @@ -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. diff --git a/force.lua b/force.lua index 9360ca8b95..afb3c4febd 100644 --- a/force.lua +++ b/force.lua @@ -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, +}) From 54c433436ce3621b0fae59f83606dafcbcf544dd Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Fri, 4 Oct 2024 16:04:56 -0700 Subject: [PATCH 2/4] remove modtools/force merged into the regular force command --- docs/modtools/force.rst | 32 --------------------- modtools/force.lua | 64 ----------------------------------------- 2 files changed, 96 deletions(-) delete mode 100644 docs/modtools/force.rst delete mode 100644 modtools/force.lua diff --git a/docs/modtools/force.rst b/docs/modtools/force.rst deleted file mode 100644 index 9f71183fa1..0000000000 --- a/docs/modtools/force.rst +++ /dev/null @@ -1,32 +0,0 @@ -modtools/force -============== - -.. dfhack-tool:: - :summary: Trigger game events. - :tags: dev - -This tool triggers events like megabeasts, caravans, and migrants. - -Usage ------ - -:: - - -eventType event - specify the type of the event to trigger - examples: - Megabeast - Migrants - Caravan - Diplomat - WildlifeCurious - WildlifeMischievous - WildlifeFlier - NightCreature - -civ entity - specify the civ of the event, if applicable - examples: - player - MOUNTAIN - EVIL - 28 diff --git a/modtools/force.lua b/modtools/force.lua deleted file mode 100644 index eb49b91552..0000000000 --- a/modtools/force.lua +++ /dev/null @@ -1,64 +0,0 @@ --- Forces an event (caravan, migrants, etc) --- author Putnam --- edited by expwnent -local utils = require 'utils' - -local function findCiv(arg) - local entities = df.global.world.entities.all - if tonumber(arg) then return df.historical_entity.find(tonumber(arg)) end - if arg then - for eid,entity in ipairs(entities) do - if entity.entity_raw.code == arg then return entity end - end - end - return nil -end - -local validArgs = utils.invert({ - 'eventType', - 'help', - 'civ' -}) - -local args = utils.processArgs({...}, validArgs) -if args.help then - print(dfhack.script_help()) - return -end - -if not args.eventType then - error 'Specify an eventType.' -elseif not df.timed_event_type[args.eventType] then - error('Invalid eventType: ' .. args.eventType) -elseif args.eventType == 'FeatureAttack' then - qerror('Event type: FeatureAttack is not currently supported') -end - -local civ = nil --as:df.historical_entity -if args.civ == 'player' then - civ = df.historical_entity.find(df.global.plotinfo.civ_id) -elseif args.civ then - civ = findCiv(args.civ) -end -if args.civ and not civ then - error('Invalid civ: ' .. args.civ) -end -if args.eventType == 'Caravan' or args.eventType == 'Diplomat' then - if not civ then - error('Specify civ for this eventType') - end -end - -if args.eventType == 'Migrants' then - civ = df.historical_entity.find(df.global.plotinfo.civ_id) -end - -local timedEvent = df.timed_event:new() -timedEvent.type = df.timed_event_type[args.eventType] -timedEvent.season = df.global.cur_season -timedEvent.season_ticks = df.global.cur_season_tick -if civ then - timedEvent.entity = civ -end - -df.global.timed_events:insert('#', timedEvent) From d2fc7c999379a25ac4322573fc96e056777c0598 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Fri, 4 Oct 2024 16:05:28 -0700 Subject: [PATCH 3/4] update changelog --- changelog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.txt b/changelog.txt index a2d46d6fa7..e47da2ec92 100644 --- a/changelog.txt +++ b/changelog.txt @@ -41,6 +41,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 From 20cc47bfcb6012f46bf74c7a15bf991de26bb81a Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Fri, 4 Oct 2024 16:19:28 -0700 Subject: [PATCH 4/4] fix docs for latency of wildlife spawns --- docs/force.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/force.rst b/docs/force.rst index 5bc13bd7f6..fb52a15803 100644 --- a/docs/force.rst +++ b/docs/force.rst @@ -59,5 +59,5 @@ The supported event types are: - ``Megabeast`` - ``Wildlife`` -Most events happen on the next tick. The ``Wildlife`` event may take up to 14 +Most events happen on the next tick. The ``Wildlife`` event may take up to 100 ticks to take effect.