-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into WIP-pregnancy
- Loading branch information
Showing
363 changed files
with
27,223 additions
and
15,816 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.