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

New script - add to core party #1146

Merged
merged 14 commits into from
Jul 2, 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
3 changes: 2 additions & 1 deletion advtools.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
--@ module=true

local convo = reqscript('internal/advtools/convo')
local party = reqscript('internal/advtools/party')

OVERLAY_WIDGETS = {
conversation=convo.AdvRumorsOverlay,
Expand All @@ -11,7 +12,7 @@ if dfhack_flags.module then
end

local commands = {
-- mycommand=mycommand.run,
party=party.run,
}

local args = {...}
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
- `advtools`: collection of useful commands and overlays for adventure mode
- `advtools`: advtools party - promotes one of your companions to become a controllable adventurer
- `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 people, locations, and artifacts
Expand Down
14 changes: 8 additions & 6 deletions docs/advtools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,27 @@ advtools

.. dfhack-tool::
:summary: A collection of useful adventure mode tools.
:tags: adventure interface
:tags: adventure interface gameplay units

Usage
-----

::

advtools party add-core [<options>]
advtools party

Examples
--------

``advtools party add-core``
Add the selected "extra" party member to your core party.
``advtools party``
Shows a dialog prompt to promote your extra party members to your core (controllable) party.

``party`` Options
``party`` Command
-----------------

TBD
When you run this command, you will get a list of your extra party members and can choose
who to promote into your "core party", aka let you control them in the tactics mode, not
dissimilar to what you get if you create a group of adventurers during character creation.

Overlays
--------
Expand Down
56 changes: 56 additions & 0 deletions internal/advtools/party.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
--@ module=true

local dialogs = require 'gui.dialogs'
local utils = require 'utils'

local makeown = reqscript('makeown')

local viewscreen = dfhack.gui.getDFViewscreen(true)
if viewscreen._type ~= df.viewscreen_dungeonmodest then
qerror("This script can only be used during adventure mode!")
end

local function addToCoreParty(nemesis)
-- Adds them to the party core members list
local party = df.global.adventure.interactions
-- problem: the "brain" icon deciding on manual/automatic control is somewhat broken.
-- research leads me to believe the data is stored per-unit or unit ID, need to figure out
-- where that data is stored exactly. Might be one of the unknown variables?
party.party_core_members:insert('#', nemesis.figure.id)
local extra_member_idx, _ = utils.linear_index(party.party_extra_members, nemesis.figure.id)
if extra_member_idx then
party.party_extra_members:erase(extra_member_idx)
end
-- Adds them to unretire list
nemesis.flags.ADVENTURER = true

-- Make sure they're no longer nameless
local unit = df.unit.find(nemesis.figure.unit_id)
makeown.name_unit(unit)
if not nemesis.figure.name.has_name then
local old_name = nemesis.figure.name
nemesis.figure.name = unit.name:new()
old_name:delete()
end
end

local function showExtraPartyPrompt()
local choices = {}
for _, histfig_id in ipairs(df.global.adventure.interactions.party_extra_members) do
local hf = df.historical_figure.find(histfig_id)
if not hf then goto continue end
local nemesis, unit = df.nemesis_record.find(hf.nemesis_id), df.unit.find(hf.unit_id)
if not nemesis or not unit or unit.flags2.killed then goto continue end
local name = dfhack.units.getReadableName(unit)
table.insert(choices, {text=name, nemesis=nemesis, search_key=dfhack.toSearchNormalized(name)})
::continue::
end
dialogs.showListPrompt('party', "Select someone to add to your \"Core Party\" (able to assume control, able to unretire):", COLOR_WHITE,
choices, function(id, choice)
addToCoreParty(choice.nemesis)
end, nil, nil, true)
end

function run()
showExtraPartyPrompt()
end