Skip to content

Commit

Permalink
Merge pull request #861 from RosaryMala/transform-unit
Browse files Browse the repository at this point in the history
Updated transform-unit.lua to try to select the currently selected un…
  • Loading branch information
myk002 authored Oct 14, 2023
2 parents 1c67dcd + 04f561c commit 6166bb7
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions modtools/transform-unit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,17 @@ if args.clear then
return
end

if not args.unit then
error 'Specify a unit.'
local unit
if args.unit then
unit = df.unit.find(tonumber(args.unit))
else
unit = dfhack.gui.getSelectedUnit(true)
end
if not unit then
error 'Select or specify a valid unit'
return
end
local unit_id = unit.id

if not args.duration then
args.duration = 'forever'
Expand All @@ -78,11 +86,10 @@ local raceIndex
local race
local caste
if args.untransform then
local unit = df.unit.find(tonumber(args.unit))
raceIndex = normalRace[args.unit].race
raceIndex = normalRace[unit_id].race
race = df.creature_raw.find(raceIndex)
caste = normalRace[args.unit].caste
normalRace[args.unit] = nil
caste = normalRace[unit_id].caste
normalRace[unit_id] = nil
else
if not args.race or not args.caste then
error 'Specficy a target form.'
Expand Down Expand Up @@ -113,13 +120,12 @@ else
end
end

local unit = df.unit.find(tonumber(args.unit))
local oldRace = unit.enemy.normal_race
local oldCaste = unit.enemy.normal_caste
if args.setPrevRace then
normalRace[args.unit] = {}
normalRace[args.unit].race = oldRace
normalRace[args.unit].caste = oldCaste
normalRace[unit_id] = {}
normalRace[unit_id].race = oldRace
normalRace[unit_id].caste = oldCaste
end
transform(unit,raceIndex,caste,args.setPrevRace)

Expand Down

0 comments on commit 6166bb7

Please sign in to comment.