Skip to content

Commit

Permalink
Merge branch 'master' into WIP-pregnancy
Browse files Browse the repository at this point in the history
  • Loading branch information
myk002 authored Aug 13, 2024
2 parents 04d2b66 + 9575540 commit c144ed3
Show file tree
Hide file tree
Showing 363 changed files with 27,223 additions and 15,816 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ jobs:
test:
uses: DFHack/dfhack/.github/workflows/test.yml@develop
with:
scripts_repo: ${{ github.repository }}
scripts_ref: ${{ github.ref }}
secrets: inherit

docs:
uses: DFHack/dfhack/.github/workflows/build-linux.yml@develop
with:
scripts_repo: ${{ github.repository }}
scripts_ref: ${{ github.ref }}
artifact-name: docs
platform-files: false
Expand All @@ -22,5 +24,6 @@ jobs:
lint:
uses: DFHack/dfhack/.github/workflows/lint.yml@develop
with:
scripts_repo: ${{ github.repository }}
scripts_ref: ${{ github.ref }}
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.6.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.27.0
rev: 0.29.1
hooks:
- id: check-github-workflows
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.5.4
rev: v1.5.5
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.6.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
132 changes: 42 additions & 90 deletions adaptation.lua
Original file line number Diff line number Diff line change
@@ -1,112 +1,64 @@
-- Original opening comment before lua adaptation
-- View or set cavern adaptation levels
-- based on removebadthoughts.rb
-- Rewritten by TBSTeun using OpenAI GPT from adaptation.rb

local args = {...}

local mode = args[1] or 'help'
local who = args[2]
local value = args[3]
local argparse = require('argparse')

local function print_color(color, s)
dfhack.color(color)
dfhack.print(s)
dfhack.color(COLOR_RESET)
end

local function usage(s)
if s then
dfhack.printerr(s)
local function show_one(unit)
local t = dfhack.units.getMiscTrait(unit, df.misc_trait_type.CaveAdapt)
local val = t and t.value or 0
print_color(COLOR_RESET, ('%s has an adaptation level of '):
format(dfhack.units.getReadableName(unit)))
if val <= 399999 then
print_color(COLOR_GREEN, ('%d\n'):format(val))
elseif val <= 599999 then
print_color(COLOR_YELLOW, ('%d\n'):format(val))
else
print_color(COLOR_RED, ('%d\n'):format(val))
end
print(dfhack.script_help())
end

local function set_adaptation_value(unit, v)
if not dfhack.units.isCitizen(unit) or not dfhack.units.isAlive(unit) then
return 0
end

for _, t in ipairs(unit.status.misc_traits) do
if t.id == df.misc_trait_type.CaveAdapt then
if mode == 'show' then
print_color(COLOR_RESET, ('Unit %s (%s) has an adaptation of '):format(unit.id, dfhack.TranslateName(dfhack.units.getVisibleName(unit))))
if t.value <= 399999 then
print_color(COLOR_GREEN, ('%s\n'):format(t.value))
elseif t.value <= 599999 then
print_color(COLOR_YELLOW, ('%s\n'):format(t.value))
else
print_color(COLOR_RED, ('%s\n'):format(t.value))
end
local function set_one(unit, value)
local t = dfhack.units.getMiscTrait(unit, df.misc_trait_type.CaveAdapt, true)
print(('%s has changed from an adaptation level of %d to %d'):
format(dfhack.units.getReadableName(unit), t.value, value))
t.value = value
end

return 0
elseif mode == 'set' then
print(('Unit %s (%s) changed from %s to %s'):format(unit.id, dfhack.TranslateName(dfhack.units.getVisibleName(unit)), t.value, v))
t.value = v
return 1
end
end
end
if mode == 'show' then
print_color(COLOR_RESET, ('Unit %s (%s) has an adaptation of '):format(unit.id, dfhack.TranslateName(dfhack.units.getVisibleName(unit))))
print_color(COLOR_GREEN, '0\n')
elseif mode == 'set' then
local new_trait = dfhack.units.getMiscTrait(unit, df.misc_trait_type.CaveAdapt, true)
new_trait.id = df.misc_trait_type.CaveAdapt
new_trait.value = v
print(('Unit %s (%s) changed from 0 to %d'):format(unit.id, dfhack.TranslateName(dfhack.units.getVisibleName(unit)), v))
return 1
local function get_units(all)
local units = all and dfhack.units.getCitizens() or {dfhack.gui.getSelectedUnit(true)}
if #units == 0 then
qerror('Please select a unit or specify the --all option')
end

return 0
return units
end

if mode == 'help' then
usage()
return
elseif mode ~= 'show' and mode ~= 'set' then
usage(('Invalid mode %s: must be either "show" or "set"'):format(mode))
return
end
local help, all = false, false
local positionals = argparse.processArgsGetopt({...}, {
{'a', 'all', handler=function() all = true end},
{'h', 'help', handler=function() help = true end}
})

if not who then
usage('Target not specified')
return
elseif who ~= 'him' and who ~= 'all' then
usage(('Invalid target %s'):format(who))
if help then
print(dfhack.script_help())
return
end

if mode == 'set' then
if not value then
usage('Value not specified')
return
elseif not tonumber(value) then
usage(('Invalid value %s'):format(value))
return
if not positionals[1] or positionals[1] == 'show' then
for _, unit in ipairs(get_units(all)) do
show_one(unit)
end

value = tonumber(value)
if value < 0 or value > 800000 then
usage(('Value must be between 0 and 800000 (inclusive), input value was %s'):format(value))
elseif positionals[1] == 'set' then
local value = argparse.nonnegativeInt(positionals[2], 'value')
if value > 800000 then
dfhack.printerr('clamping value to 800,000')
value = 800000
end
end

if who == 'him' then
local u = dfhack.gui.getSelectedUnit(true)
if u then
set_adaptation_value(u, value)
else
dfhack.printerr('Please select a dwarf ingame')
end
elseif who == 'all' then
local num_set = 0

for _, uu in ipairs(df.global.world.units.all) do
num_set = num_set + set_adaptation_value(uu, value)
end

if num_set > 0 then
print(('%s units changed'):format(num_set))
for _, unit in ipairs(get_units(all)) do
set_one(unit, value)
end
else
qerror('unknown command: ' .. positionals[1])
end
87 changes: 35 additions & 52 deletions add-thought.lua
Original file line number Diff line number Diff line change
@@ -1,47 +1,41 @@
-- Adds emotions to creatures.
--@ module = true

--[====[
add-thought
===========
Adds a thought or emotion to the selected unit. Can be used by other scripts,
or the gui invoked by running ``add-thought -gui`` with a unit selected.
]====]

local utils=require('utils')
local script = require('gui.script')
local utils = require('utils')

function addEmotionToUnit(unit,thought,emotion,severity,strength,subthought)
local emotions=unit.status.current_soul.personality.emotions
if not (tonumber(emotion)) then
emotion=df.emotion_type[emotion] --luacheck: retype
local personality = unit.status.current_soul.personality
local emotions = personality.emotions
if not tonumber(emotion) then
emotion = df.emotion_type[emotion] --luacheck: retype
end
severity = tonumber(severity) or 0
local properThought = tonumber(thought) or df.unit_thought_type[thought]
local properSubthought = tonumber(subthought)
if not properThought or not df.unit_thought_type[properThought] then
for k,syn in ipairs(df.global.world.raws.syndromes.all) do
if syn.syn_name==thought then
for _,syn in ipairs(df.global.world.raws.syndromes.all) do
if syn.syn_name == thought then
properThought = df.unit_thought_type.Syndrome
properSubthought = syn.id
break
end
end
end
emotions:insert('#',{new=df.unit_personality.T_emotions,
type=tonumber(emotion),
unk2=1,
strength=tonumber(strength),
thought=properThought,
subthought=properSubthought,
severity=tonumber(severity),
unk7=0,
year=df.global.cur_year,
year_tick=df.global.cur_year_tick
emotions:insert('#', {
new=df.personality_moodst,
type=emotion,
strength=1,
relative_strength=tonumber(strength),
thought=properThought,
subthought=properSubthought,
severity=severity,
year=df.global.cur_year,
year_tick=df.global.cur_year_tick
})
local divider=df.emotion_type.attrs[emotion].divider
if divider~=0 then
unit.status.current_soul.personality.stress=unit.status.current_soul.personality.stress+math.ceil(severity/df.emotion_type.attrs[emotion].divider)
if divider ~= 0 then
personality.stress = personality.stress + math.ceil(severity/df.emotion_type.attrs[emotion].divider)
end
end

Expand All @@ -56,48 +50,37 @@ local validArgs = utils.invert({
})

function tablify(iterableObject)
local t={}
local t = {}
for k,v in ipairs(iterableObject) do
t[k] = v~=nil and v or 'nil'
end
return t
end

if moduleMode then
return
if dfhack_flags.module then
return
end

local args = utils.processArgs({...}, validArgs)

local unit = args.unit and df.unit.find(tonumber(args.unit)) or dfhack.gui.getSelectedUnit(true)

if not unit then qerror('A unit must be specified or selected.') end

if args.gui then
local script=require('gui.script')
script.start(function()
local tok,thought=script.showListPrompt('emotions','Which thought?',COLOR_WHITE,tablify(df.unit_thought_type),10,true)
if tok then
local eok,emotion=script.showListPrompt('emotions','Which emotion?',COLOR_WHITE,tablify(df.emotion_type),10,true)
if eok then
local sok,severity=script.showInputPrompt('emotions','At what severity?',COLOR_WHITE,'0')
if sok then
local stok,strength=script.showInputPrompt('emotions','At what strength?',COLOR_WHITE,'0')
if stok then
addEmotionToUnit(unit,thought,emotion,severity,strength,0)
end
end
end
end
end)
script.start(function()
local tok,thought = script.showListPrompt('emotions','Which thought?',COLOR_WHITE,tablify(df.unit_thought_type),10,true)
if not tok then return end
local eok,emotion = script.showListPrompt('emotions','Which emotion?',COLOR_WHITE,tablify(df.emotion_type),10,true)
if not eok then return end
local stok,strength = script.showInputPrompt('emotions','At what strength? 1 (Slight), 2 (Moderate), 5 (Strong), 10 (Intense).',COLOR_WHITE,'0')
if not stok then return end
addEmotionToUnit(unit,thought,emotion,0,strength,0)
end)
else
local thought = args.thought or 180

local thought = args.thought or df.unit_thought_type.NeedsUnfulfilled
local emotion = args.emotion or -1

local severity = args.severity or 0

local subthought = args.subthought or 0

local strength = args.strength or 0

addEmotionToUnit(unit,thought,emotion,severity,strength,subthought)
Expand Down
45 changes: 0 additions & 45 deletions adv-fix-sleepers.lua

This file was deleted.

Loading

0 comments on commit c144ed3

Please sign in to comment.