2015-05-09 00:35:19 -06:00
|
|
|
-- makes creatures [in]fertile, by modifying orientation
|
|
|
|
-- usage: fix-ster [fert|ster] [all|animals|only:<creature>]
|
2015-06-22 21:36:50 -06:00
|
|
|
-- original author: Tacomagic
|
|
|
|
-- minor fixes by PeridexisErrant, Lethosor
|
|
|
|
--@ module = true
|
2015-05-09 00:35:19 -06:00
|
|
|
|
|
|
|
--[[
|
|
|
|
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
|
|
|
|
]]--
|
|
|
|
|
2015-06-22 21:36:50 -06:00
|
|
|
function changeorient(unit, ori)
|
|
|
|
--Sets the fertility flag based on gender.
|
|
|
|
if not unit.status.current_soul then
|
2015-05-09 00:35:19 -06:00
|
|
|
return
|
|
|
|
end
|
|
|
|
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
|
|
|
|
end
|
|
|
|
|
2015-06-22 21:36:50 -06:00
|
|
|
function changelots(creatures, ori, silent)
|
|
|
|
local v, unit
|
2015-05-09 00:35:19 -06:00
|
|
|
local c = 0
|
|
|
|
--loops through indexes in creatures table and changes orientation flags
|
2015-06-22 21:36:50 -06:00
|
|
|
for _, v in ipairs(creatures) do
|
2015-05-09 00:35:19 -06:00
|
|
|
unit = df.global.world.units.active[v]
|
|
|
|
changeorient(unit,ori)
|
|
|
|
c = c + 1
|
|
|
|
end
|
2015-06-22 21:36:50 -06:00
|
|
|
if not silent then
|
|
|
|
print("Changed " .. c .. " creatures.")
|
|
|
|
end
|
2015-05-09 00:35:19 -06:00
|
|
|
end
|
|
|
|
|
2015-06-22 21:36:50 -06:00
|
|
|
function process_args(args)
|
|
|
|
local n, v, ori, crename, crenum
|
2015-05-09 00:35:19 -06:00
|
|
|
local creatures = {}
|
|
|
|
--Checks for any arguments at all.
|
2015-06-22 21:36:50 -06:00
|
|
|
if args == nil or #args == 0 then
|
2015-05-09 00:35:19 -06:00
|
|
|
print("No arguments. Usage is: fixster <fert|ster> [all|animals|only:<creature>]")
|
|
|
|
return
|
|
|
|
end
|
2015-06-22 21:36:50 -06:00
|
|
|
for i, a in pairs(args) do
|
|
|
|
args[i] = tostring(a):lower()
|
|
|
|
end
|
|
|
|
if args[1]:sub(1, 1) == "s" then -- sterile
|
2015-05-09 00:35:19 -06:00
|
|
|
ori = false
|
2015-06-22 21:36:50 -06:00
|
|
|
elseif args[1]:sub(1, 1) == "f" then -- fertile
|
2015-05-09 00:35:19 -06:00
|
|
|
ori = true
|
|
|
|
else
|
2015-06-22 21:36:50 -06:00
|
|
|
qerror("Unrecognised first argument: " .. args[1] .. ". Aborting.")
|
2015-05-09 00:35:19 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
--Checks for the existence of the second argument. If it's missing, uses selected unit (if any)
|
2015-06-22 21:36:50 -06:00
|
|
|
if args[2] == nil then
|
|
|
|
unit = dfhack.gui.getSelectedUnit()
|
|
|
|
if not unit then return end
|
|
|
|
changeorient(unit, ori)
|
2015-05-09 00:35:19 -06:00
|
|
|
print('Changed selected creature.')
|
|
|
|
|
|
|
|
--ALL arg processing
|
2015-06-22 21:36:50 -06:00
|
|
|
elseif args[2] == "all" then
|
2015-05-09 00:35:19 -06:00
|
|
|
--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
|
2015-06-22 21:36:50 -06:00
|
|
|
elseif args[2] == "animals" then
|
2015-05-09 00:35:19 -06:00
|
|
|
--Create a table of all creature indexes except dwarves on the current map
|
|
|
|
for n,v in ipairs(df.global.world.units.active) do
|
2015-06-22 21:36:50 -06:00
|
|
|
if v.race ~= df.global.ui.race_id then
|
2015-05-09 00:35:19 -06:00
|
|
|
table.insert(creatures,n)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
changelots(creatures,ori)
|
|
|
|
|
|
|
|
-- ONLY:<creature> arg processing
|
2015-06-22 21:36:50 -06:00
|
|
|
elseif args[2]:sub(1,4) == "only" then
|
|
|
|
crename = args[2]:sub(6):upper()
|
2015-05-09 00:35:19 -06:00
|
|
|
|
|
|
|
--Search raws for creature
|
|
|
|
for k,v in pairs(df.global.world.raws.creatures.all) do
|
2015-06-22 21:36:50 -06:00
|
|
|
if v.creature_id == crename then
|
2015-05-09 00:35:19 -06:00
|
|
|
crenum = k
|
|
|
|
end
|
|
|
|
end
|
|
|
|
--If no match, abort
|
|
|
|
if crenum == nil then
|
2015-06-22 21:36:50 -06:00
|
|
|
qerror("Creature not found. Check spelling.")
|
2015-05-09 00:35:19 -06:00
|
|
|
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
|
2015-06-22 21:36:50 -06:00
|
|
|
qerror("Unrecognised optional argument. Aborting")
|
2015-05-09 00:35:19 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-06-22 21:36:50 -06:00
|
|
|
if not moduleMode then
|
|
|
|
local args = table.pack(...)
|
|
|
|
process_args(args)
|
|
|
|
end
|