Skip to content

Commit e80d330

Browse files
authored
Merge pull request #1509 from amade-w/symbol-unstick
Add new tool `fix/symbol-unstick`
2 parents f72ccf6 + bb77b1e commit e80d330

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Template for new versions:
2727
# Future
2828

2929
## New Tools
30+
- `fix/symbol-unstick`: unstick noble symbols that cannot be re-designated.
3031
- `resize-armor`: resize armor or clothing item to any creature size.
3132

3233
## New Features

docs/fix/symbol-unstick.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
fix/symbol-unstick
2+
==================
3+
4+
.. dfhack-tool::
5+
:summary: Unstick noble symbols that cannot be re-designated.
6+
:tags: fort bugfix items
7+
8+
Remove symbol designation from artifacts that cannot be re-designated
9+
after the noble's promotion to a higher position.
10+
11+
Usage
12+
-----
13+
14+
``fix/symbol-unstick``
15+
16+
Select an artifact that was designated as a noble's symbol and run the
17+
command to remove its designation as a symbol. The operation will only
18+
be performed if the symbol is claimed by a vacated noble position.

fix/symbol-unstick.lua

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
-- Unstick noble symbols that cannot be re-designated.
2+
3+
local utils = require('utils')
4+
5+
local function GetArtifact(item)
6+
local artifact
7+
for _, generalRef in ipairs(item.general_refs) do
8+
if df.general_ref_is_artifactst:is_instance(generalRef) then
9+
artifact = df.artifact_record.find(generalRef.artifact_id)
10+
break
11+
end
12+
end
13+
local civ_id = df.global.plotinfo.civ_id
14+
-- Check if selected item is claimed by current site's civ.
15+
local entClaim_idx = artifact and utils.linear_index(artifact.entity_claims, civ_id)
16+
if artifact and entClaim_idx then
17+
return artifact, entClaim_idx
18+
end
19+
return nil
20+
end
21+
22+
local function UnstickSymbol(artifact, entClaim_idx)
23+
local civEntity = df.historical_entity.find(df.global.plotinfo.civ_id)
24+
local idx = utils.linear_index(civEntity.artifact_claims, artifact.id, 'artifact_id')
25+
-- Check if selected item is a symbol.
26+
if idx and civEntity.artifact_claims[idx].claim_type == df.artifact_claim_type.Symbol then
27+
local position_idx = civEntity.artifact_claims[idx].symbol_claim_id
28+
-- Check if symbol's position has been vacated.
29+
if civEntity.positions.assignments[position_idx].histfig == -1 then
30+
-- Erase claim from the entity and its reference in the artifact's record.
31+
-- Note: it's also possible to re-assign symbol by changing symbol_claim_id
32+
-- to point to the appropriate idx in civEntity.positions.assignments
33+
civEntity.artifact_claims:erase(idx)
34+
artifact.entity_claims:erase(entClaim_idx)
35+
return true
36+
end
37+
end
38+
return false
39+
end
40+
41+
local function Main(args)
42+
if args[1] == 'help' then
43+
print(dfhack.script_help())
44+
return
45+
end
46+
local item = dfhack.gui.getSelectedItem(true)
47+
if not item then
48+
qerror('No item selected.')
49+
end
50+
local artifact, entClaim_idx = GetArtifact(item)
51+
if artifact then
52+
if UnstickSymbol(artifact, entClaim_idx) then
53+
print('Symbol designation removed from selected item.')
54+
local strItemName = item and dfhack.items.getReadableDescription(item)
55+
print(('%s can now be re-designated as a symbol of nobility.'):format(strItemName))
56+
else
57+
qerror('Selected item is not a defunct symbol of the current site\'s civilization.')
58+
end
59+
else
60+
qerror('Selected item is not an artifact claimed by the current site\'s civilization.')
61+
end
62+
end
63+
64+
if not dfhack.isSiteLoaded() and not dfhack.world.isFortressMode() then
65+
qerror('This script requires the game to be in fortress mode.')
66+
end
67+
68+
Main({...})

0 commit comments

Comments
 (0)