Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bodyswap to work on the latest adv-beta #1136

Merged
merged 7 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 6 additions & 34 deletions bodyswap.lua
Crystalwarrior marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ end

function setNewAdvNemFlags(nem)
nem.flags.ACTIVE_ADVENTURER = true
nem.flags.RETIRED_ADVENTURER = false
nem.flags.ADVENTURER = true
end

Expand All @@ -30,16 +29,12 @@ function clearNemesisFromLinkedSites(nem)
end
for _, link in ipairs(nem.figure.site_links) do
local site = df.world_site.find(link.site)
for i = #site.unk_1.nemesis - 1, 0, -1 do
if site.unk_1.nemesis[i] == nem.id then
site.unk_1.nemesis:erase(i)
end
end
utils.erase_sorted(site.populace.nemesis, nem.id)
end
end

function createNemesis(unit)
local nemesis = reqscript('modtools/create-unit').createNemesis(unit, unit.civ_id)
local nemesis = unit:create_nemesis(1, 1)
nemesis.figure.flags.never_cull = true
return nemesis
end
Expand Down Expand Up @@ -116,30 +111,6 @@ function swapAdvUnit(newUnit)
return
end

local activeUnits = df.global.world.units.active
local oldUnitIndex
if activeUnits[0] == oldUnit then
oldUnitIndex = 0
else -- unlikely; this is just in case
for i, u in ipairs(activeUnits) do
if u == oldUnit then
oldUnitIndex = i
break
end
end
end
local newUnitIndex
for i, u in ipairs(activeUnits) do
if u == newUnit then
newUnitIndex = i
break
end
end

if not newUnitIndex then
qerror("Target unit index not found!")
end

local newNem = dfhack.units.getNemesis(newUnit) or createNemesis(newUnit)
if not newNem then
qerror("Failed to obtain target nemesis!")
Expand All @@ -149,9 +120,10 @@ function swapAdvUnit(newUnit)
setNewAdvNemFlags(newNem)
configureAdvParty(newNem)
df.global.adventure.player_id = newNem.id
activeUnits[newUnitIndex] = oldUnit
activeUnits[oldUnitIndex] = newUnit
df.global.world.units.adv_unit = newUnit
oldUnit.idle_area:assign(oldUnit.pos)

dfhack.gui.revealInDwarfmodeMap(xyz2pos(dfhack.units.getPosition(newUnit)), true)
end

if not dfhack_flags.module then
Crystalwarrior marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -161,7 +133,7 @@ if not dfhack_flags.module then

local unit = args.unit and df.unit.find(tonumber(args.unit)) or dfhack.gui.getSelectedUnit()
if not unit then
print("Enter the following if you require assistance: bodyswap -help")
print("Enter the following if you require assistance: help bodyswap")
if args.unit then
qerror("Invalid unit id: " .. args.unit)
else
Expand Down
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Template for new versions:

## New Tools
- `pop-control`: (reinstated) limit the maximum size of migrant waves
- `bodyswap`: (reinstated) take control of another unit in adventure mode
- `gui/sitemap`: list and zoom to nearby people, locations, and artifacts
- `devel/tree-info`: print a visualization of tree_info data
- `fix/population-cap`: fixes the situation where you continue to get migrant waves even when you are above your configured population cap
Expand Down
2 changes: 1 addition & 1 deletion docs/bodyswap.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ bodyswap

.. dfhack-tool::
:summary: Take direct control of any visible unit.
:tags: unavailable
:tags: adventure armok units

This script allows the player to take direct control of any unit present in
adventure mode whilst giving up control of their current player character.
Expand Down