Add fix-ster by Tacomagic

Allow setting fertility or sterility of units or whole species.
develop
Peridexis Errant 2015-05-09 16:35:19 +10:00
parent d0ba6d7019
commit 939cab4451
3 changed files with 143 additions and 0 deletions

@ -8,6 +8,7 @@ DFHack Future
New plugins New plugins
New scripts New scripts
view-item-info: adds information and customisable descriptions to item viewscreens view-item-info: adds information and customisable descriptions to item viewscreens
fix-ster: changes fertility/sterility of animals or dwarves
New tweaks New tweaks
New features New features
dwarfmonitor date format can be modified (see Readme) dwarfmonitor date format can be modified (see Readme)

@ -2353,6 +2353,18 @@ To purify all elves on the map with fire (may have side-effects)::
exterminate elve magma exterminate elve magma
fix-ster
========
Utilizes the orientation tag to either fix infertile creatures or inflict
infertility on creatures that you do not want to breed. Usage::
fix-ster [fert|ster] [all|animals|only:<creature>]
``fert`` or ``ster`` is a required argument; whether to make the target fertile
or sterile. Optional arguments specify the target: no argument for the
selected unit, ``all`` for all units on the map, ``animals`` for all non-dwarf
creatures, or ``only:<creature>`` to only process matching creatures.
fortplan fortplan
======== ========
Usage: fortplan [filename] Usage: fortplan [filename]

@ -0,0 +1,130 @@
-- makes creatures [in]fertile, by modifying orientation
-- usage: fix-ster [fert|ster] [all|animals|only:<creature>]
-- by Tacomagic (minor fixes by PeridexisErrant)
--[[
This script utilizes the orientation tag to either fix infertile creatures
or inflict infertility on creatures that you do not want to breed
Required arg:
fert: sets the flag to assure creature(s) are fertile
ster: sets the flag to assure creature(s) are sterile
Optional args:
<no arg> the script will only process the currently selected creature
all: process all creatures currently on the map
animals: processes everything but dwarves on the map
only:<creature>: processes all of the creatures matching the specified creature on the map
]]--
function getunit()
local unit
unit=dfhack.gui.getSelectedUnit()
if unit==nil then
print("No unit under cursor.")
return
end
return unit
end
function changeorient(unit,ori)
--Sets the fertility flag based on gender.
if unit.sex == 0 then
unit.status.current_soul.orientation_flags.marry_male=ori
else
unit.status.current_soul.orientation_flags.marry_female=ori
end
return
end
function changelots(creatures,ori)
local v
local unit
local c = 0
--loops through indexes in creatures table and changes orientation flags
for _,v in ipairs(creatures) do
unit = df.global.world.units.active[v]
changeorient(unit,ori)
c = c + 1
end
print("Changed "..c.. " creatures.")
return
end
function process_args(arg)
local n,v
local ori
local creatures = {}
local crenum
--Checks for any arguments at all.
if arg==nil then
print("No arguments. Usage is: fixster <fert|ster> [all|animals|only:<creature>]")
return
end
if string.lower(arg[1])=="ster" then
ori = false
elseif string.lower(arg[1])=="fert" then
ori = true
else
print("Unrecognised first argument. Aborting.")
return
end
--Checks for the existence of the second argument. If it's missing, uses selected unit (if any)
if arg[2]==nil then
unit = getunit()
if unit == nil then return end
changeorient(unit,ori)
print('Changed selected creature.')
--ALL arg processing
elseif string.lower(arg[2])=="all" then
--Create table of all current unit indexes
for n,v in ipairs(df.global.world.units.active) do
table.insert(creatures,n)
end
changelots(creatures,ori)
--ANIMALS arg processing
elseif string.lower(arg[2])=="animals" then
--Create a table of all creature indexes except dwarves on the current map
for n,v in ipairs(df.global.world.units.active) do
if v.race~=df.global.ui.race_id then
table.insert(creatures,n)
end
end
changelots(creatures,ori)
-- ONLY:<creature> arg processing
elseif string.lower(string.sub(arg[2],1,4))=="only" then
creidx = string.upper(string.sub(arg[2],6))
print(string.upper(string.sub(arg[2],6)))
--Search raws for creature
for k,v in pairs(df.global.world.raws.creatures.all) do
if v.creature_id==creidx then
crenum = k
end
end
--If no match, abort
if crenum == nil then
print("Creature not found. Check spelling.")
return
end
--create a table of all the matching creature indexes on the map for processing
for n,v in ipairs(df.global.world.units.active) do
if v.race == crenum then
table.insert(creatures,n)
end
end
changelots(creatures,ori)
else
print("Unrecognised optional argument. Aborting")
return
end
return
end
local arg = table.pack(...)
process_args(arg)