Skip to content

Commit

Permalink
Merge branch 'DFHack:master' into patch-6
Browse files Browse the repository at this point in the history
  • Loading branch information
TymurGubayev authored Jan 1, 2024
2 parents 0b37a9a + 53fdcd8 commit 00a7ed5
Show file tree
Hide file tree
Showing 339 changed files with 17,303 additions and 6,835 deletions.
70 changes: 19 additions & 51 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,56 +3,24 @@ name: Build
on: [push, pull_request]

jobs:
test:
uses: DFHack/dfhack/.github/workflows/test.yml@develop
with:
scripts_ref: ${{ github.ref }}
secrets: inherit

docs:
runs-on: ubuntu-22.04
steps:
- name: Set up Python 3
uses: actions/setup-python@v2
with:
python-version: 3
- name: Install dependencies
run: |
pip install 'sphinx<4.4.0'
- name: Clone scripts
uses: actions/checkout@v1
- name: Set up DFHack
run: |
git clone https://github.com/DFHack/dfhack.git $HOME/dfhack --depth 1 --branch develop
git -C $HOME/dfhack submodule update --init --depth 1 --remote plugins/stonesense library/xml
rmdir $HOME/dfhack/scripts
ln -sv $(pwd) $HOME/dfhack/scripts
- name: Build docs
run: |
sphinx-build -W --keep-going -j3 --color $HOME/dfhack html
- name: Check for missing docs
if: success() || failure()
run: python $HOME/dfhack/ci/script-docs.py .
- name: Upload docs
if: success() || failure()
uses: actions/upload-artifact@master
with:
name: docs
path: html
uses: DFHack/dfhack/.github/workflows/build-linux.yml@develop
with:
scripts_ref: ${{ github.ref }}
artifact-name: docs
platform-files: false
common-files: false
docs: true
secrets: inherit

lint:
runs-on: ubuntu-22.04
steps:
- name: Set up Python 3
uses: actions/setup-python@v2
with:
python-version: 3
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install lua5.3
- name: Clone scripts
uses: actions/checkout@v1
- name: Set up DFHack
run: |
git clone https://github.com/DFHack/dfhack.git $HOME/dfhack --depth 1 --branch develop
rmdir $HOME/dfhack/scripts
ln -sv $(pwd) $HOME/dfhack/scripts
- name: Check whitespace
run: python $HOME/dfhack/ci/lint.py --git-only --github-actions
- name: Check Lua syntax
if: success() || failure()
run: python $HOME/dfhack/ci/script-syntax.py --ext=lua --cmd="luac5.3 -p" --github-actions
uses: DFHack/dfhack/.github/workflows/lint.yml@develop
with:
scripts_ref: ${{ github.ref }}
secrets: inherit
11 changes: 11 additions & 0 deletions .github/workflows/clean-cache.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Clean up PR caches

on:
pull_request_target:
types:
- closed

jobs:
cleanup:
uses: DFHack/dfhack/.github/workflows/clean-cache.yml@develop
secrets: inherit
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ci:
repos:
# shared across repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
Expand All @@ -20,11 +20,11 @@ repos:
args: ['--fix=lf']
- id: trailing-whitespace
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.21.0
rev: 0.27.2
hooks:
- id: check-github-workflows
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.4.2
rev: v1.5.4
hooks:
- id: forbid-tabs
exclude_types:
Expand All @@ -34,6 +34,6 @@ repos:
- json
# specific to scripts:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: forbid-new-submodules
3 changes: 1 addition & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DESTINATION ${DFHACK_DATA_DESTINATION}
FILES_MATCHING PATTERN "*.lua"
PATTERN "*.rb"
PATTERN "*.json"
PATTERN "3rdparty" EXCLUDE
PATTERN "scripts/docs" EXCLUDE
PATTERN "scripts/test" EXCLUDE
)

Expand Down
29 changes: 1 addition & 28 deletions add-recipe.lua
Original file line number Diff line number Diff line change
@@ -1,25 +1,4 @@
-- Script to add unknown crafting recipes to the player's civ.
--[====[
add-recipe
==========
Adds unknown weapon and armor crafting recipes to your civ.
E.g. some civilizations never learn to craft high boots. This script can
help with that, and more. Only weapons, armor, and tools are currently supported;
things such as instruments are not. Available options:
* ``add-recipe all`` adds *all* available weapons and armor, including exotic items
like blowguns, two-handed swords, and capes.
* ``add-recipe native`` adds only native (but unknown) crafting recipes. Civilizations
pick randomly from a pool of possible recipes, which means not all civs get
high boots, for instance. This command gives you all the recipes your
civilisation could have gotten.
* ``add-recipe single <item token>`` adds a single item by the given
item token. For example::
add-recipe single SHOES:ITEM_SHOES_BOOTS
]====]

local itemDefs = df.global.world.raws.itemdefs
local resources = df.historical_entity.find(df.global.plotinfo.civ_id).resources
Expand Down Expand Up @@ -125,7 +104,6 @@ function addItems(category, exotic)
return added
end


function printItems(itemList)
for _, v in ipairs(itemList) do
local v = v --as:df.itemdef_weaponst
Expand Down Expand Up @@ -192,10 +170,5 @@ elseif (cmd == "native") then
elseif (cmd == "single") then
addSingleItem(args[2])
else
print("Available options:\n"
.."all: adds all supported crafting recipes.\n"
.."native: adds only unknown native recipes (eg. high boots for "
.."some dwarves)\n"
.."single: adds a specific item by itemstring (eg. "
.."SHOES:ITEM_SHOES_BOOTS)")
print(dfhack.script_help())
end
27 changes: 4 additions & 23 deletions assign-minecarts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,12 @@
--@ module = true

local argparse = require('argparse')
local quickfort = reqscript('quickfort')

-- ensures the list of available minecarts has been calculated by the game
local function refresh_ui_hauling_vehicles()
local qfdata
if #df.global.plotinfo.hauling.routes > 0 then
-- if there is an existing route, move to the vehicle screen and back
-- out to force the game to scan for assignable minecarts
qfdata = 'hv^^'
else
-- if no current routes, create a route, move to the vehicle screen,
-- back out, and remove the route. The extra "px" is in the string in
-- case the user has the confirm plugin enabled. "p" pauses the plugin
-- and "x" retries the route deletion.
qfdata = 'hrv^xpx^'
end
quickfort.apply_blueprint{mode='config', data=qfdata}
end

function get_free_vehicles()
refresh_ui_hauling_vehicles()
local free_vehicles = {}
for _,minecart in ipairs(df.global.plotinfo.hauling.vehicles) do
if minecart and minecart.route_id == -1 then
table.insert(free_vehicles, minecart)
for _,vehicle in ipairs(df.global.world.vehicles.active) do
if vehicle and vehicle.route_id == -1 then
table.insert(free_vehicles, vehicle)
end
end
return free_vehicles
Expand Down Expand Up @@ -136,7 +117,7 @@ local function all(quiet)
end
end

local function do_help()
local function do_help(_)
print(dfhack.script_help())
end

Expand Down
34 changes: 19 additions & 15 deletions autofish.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- handles automatic fishing jobs to limit the number of fish the fortress keeps on hand
-- autofish [enable | disable] <max> [min] [--include-raw | -r]
-- autofish [enable | disable] <max> [min] [<options>]

--@ enable=true
--@ module=true
Expand Down Expand Up @@ -73,19 +73,21 @@ end
function toggle_fishing_labour(state)
-- pass true to state to turn on, otherwise disable
-- find all work details that have fishing enabled:
local work_details = df.global.plotinfo.hauling.work_details
local work_details = df.global.plotinfo.labor_info.work_details
for _,v in pairs(work_details) do
if v.allowed_labors.FISH then
-- set limited to true just in case a custom work detail is being
-- changed, to prevent *all* dwarves from fishing.
v.work_detail_flags.limited = true
v.work_detail_flags.enabled = state
v.work_detail_flags.mode = state and
df.work_detail_mode.OnlySelectedDoesThis or df.work_detail_mode.NobodyDoesThis

-- workaround to actually enable labours
-- since the work details are not actually applied unless a button
-- is clicked on the work details screen, we have to manually set
-- unit labours
for _,v2 in ipairs(v.assigned_units) do
-- find unit by ID and toggle fishing
local unit = df.unit.find(v2)
unit.status.labors.FISH = state
if unit then
unit.status.labors.FISH = state
end
end
end
end
Expand Down Expand Up @@ -204,13 +206,17 @@ if dfhack_flags and dfhack_flags.enable then
args = {dfhack_flags.enable_state and "enable" or "disable"}
end

-- find flags in args:
-- handle options flags
local positionals = argparse.processArgsGetopt(args,
{{"r", "toggle-raw",
handler=function() s_useRaw = not s_useRaw end}
{{"r", "raw", hasArg=true,
handler=function(optArg)
local val = argparse.boolean(optArg, "raw")
set_useRaw(val)
end}
})

load_state()
-- handle the rest of the arguments
if positionals[1] == "enable" then
enabled = true

Expand All @@ -224,18 +230,16 @@ elseif positionals[1] == "status" then
print_status()
return

-- positionals is an empty table if no positional arguments are set
elseif positionals ~= nil then
-- positionals is a number?
-- check to see if passed args are numbers
if positionals[1] and tonumber(positionals[1]) then
-- assume we're changing setting:
local newval = tonumber(positionals[1])
set_maxFish(newval)
if not positionals[2] then
set_minFish(math.floor(newval * 0.75))
end
else
-- invalid or no argument
return
end

if positionals[2] and tonumber(positionals[2]) then
Expand Down
66 changes: 0 additions & 66 deletions autounsuspend.lua

This file was deleted.

Loading

0 comments on commit 00a7ed5

Please sign in to comment.